package com.fractalist.man.web.action;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.nutz.json.Json;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.fractalist.base.cache.Cache;
import com.fractalist.base.core.constants.SystemConstants;
import com.fractalist.base.core.decode.Base64;
import com.fractalist.base.core.model.JsonErrorResponse;
import com.fractalist.base.core.model.JsonSuccessResponse;
import com.fractalist.base.core.utils.MD5Util;
import com.fractalist.base.core.utils.MyDateUtils;
import com.fractalist.base.core.utils.MyImageUtils;
import com.fractalist.base.core.web.BaseActionSupport;
import com.fractalist.man.base.Page;
import com.fractalist.man.base.SqlUtils;
import com.fractalist.man.constants.ManConstants;
import com.fractalist.man.service.IAlbumsImageCommentService;
import com.fractalist.man.service.IAlbumsImageTagService;
import com.fractalist.man.service.IAlbumsService;
import com.fractalist.man.service.IAnswerService;
import com.fractalist.man.service.IAnswerSupportService;
import com.fractalist.man.service.IArticleCollectionService;
import com.fractalist.man.service.IArticleFieldService;
import com.fractalist.man.service.IArticleService;
import com.fractalist.man.service.ICommentService;
import com.fractalist.man.service.IFilterService;
import com.fractalist.man.service.IFmService;
import com.fractalist.man.service.IImageService;
import com.fractalist.man.service.IPresentScoreService;
import com.fractalist.man.service.IQuestService;
import com.fractalist.man.service.IQuestionService;
import com.fractalist.man.service.IScoreService;
import com.fractalist.man.service.ISplashScreenService;
import com.fractalist.man.service.ITagsService;
import com.fractalist.man.service.IUserApplyService;
import com.fractalist.man.service.IUserAttentionService;
import com.fractalist.man.service.IUserFieldService;
import com.fractalist.man.service.IUserGroupService;
import com.fractalist.man.service.IUserQuestService;
import com.fractalist.man.service.IUserService;
import com.fractalist.man.service.IUserSignService;
import com.fractalist.man.service.IVersionService;
import com.fractalist.man.service.IViewBangdanService;
import com.fractalist.man.service.IViewBasearticleUnionService;
import com.fractalist.man.service.IViewBaseuserUnionService;
import com.fractalist.man.service.IVoteService;

@Controller
@Scope("prototype")
@ParentPackage("default")
@Namespace(value = "/")
@Action(value = "phone")
public class PhoneAction extends BaseActionSupport {

	private static final long serialVersionUID = -2111808911345170917L;

	private static final Logger logger = Logger.getLogger(PhoneAction.class);

	@Autowired
	private ISplashScreenService splashScreenService;
	@Autowired
	private IUserService userService;
	@Autowired
	private IAlbumsService albumsService;
	// @Autowired
	// private IAlbumsImageService albumsImageService;
	@Autowired
	private IArticleService articleService;
	@Autowired
	private IUserAttentionService userAttentionService;
	@Autowired
	private IFmService fmService;
	@Autowired
	private IArticleCollectionService articleCollectionService;
	@Autowired
	private ICommentService commentService;
	@Autowired
	private IFilterService filterService;
	@Autowired
	private IQuestionService questionService;
	@Autowired
	private IAnswerService answerService;
	@Autowired
	private IVersionService versionService;
	@Autowired
	private IUserSignService userSignService;
	// @Autowired
	// private IArticleImageService articleImageService;
	@Autowired
	private ITagsService tagsService;
	@Autowired
	private IAlbumsImageTagService albumsImageTagService;
	@Autowired
	private IAlbumsImageCommentService albumsImageCommentService;
	@Autowired
	private IQuestService questService;
	@Autowired
	private IUserQuestService userQuestService;
	@Autowired
	private IScoreService scoreService;
	@Autowired
	private IVoteService voteService;
	@Autowired
	private IPresentScoreService presentScoreService;
	@Autowired
	private IAnswerSupportService answerSupportService;
	@Autowired
	private IViewBangdanService viewBangdanService;
	@Autowired
	private IUserApplyService userApplyService;
	@Autowired
	private IUserFieldService userFieldService;
	@Autowired
	private IArticleFieldService articleFieldService;
	@Autowired
	private IViewBasearticleUnionService viewBasearticleUnionService;
	@Autowired
	private IViewBaseuserUnionService viewBaseuserUnionService;
	@Autowired
	private IUserGroupService userGroupService;
	@Autowired
	private IImageService imageService;

	private Map<String, Object> paramMap;

	private String expire = "0mn";

	private String password;

	private Long curUserId;

	private Long userId;
	private String name;
	private Integer gender;
	private Integer age;
	private String bwh;
	private String constellation;
	private String birthday;

	private String phoneNumber;
	private String platform;

	private Integer pageNumber = 1;
	private Integer pageLine = ManConstants.COMMON_PAGE_SIZE;
	private Integer state;

	private String image;
	private String fomart;
	// private String[] images;

	private Long albumId;
	private String summary;

	private Long followUserId;
	private Integer value = 0;
	private Integer valueNum = 1;

	private Long columnId;

	private Long articleId;
	private String content;

	private Long questionId;

	private String title;
	private List<Map<String, Object>> images;
	private List<Map<String, Object>> tags;

	private String endDate;
	private String startDate;

	private Boolean isPrivate = false;

	private Long imageId;

	private Long questId;

	private String keyword;

	private String icon;
	private Long girlId;
	private Integer score;
	private Long answerId;

	private Integer type;
	private Integer days;

	private String girlCity;

	private Integer bust;
	private Integer waistline;
	private Integer hip;

	private MyImageUtils imageUtils = new MyImageUtils();

	// TODO
	// 参数配置结束------//

	/**
	 * 安全起见，去掉user的map对象中的password属性
	 * 
	 * @param user
	 */
	public void removePasswordFromUser(Map<String, Object> user) {
		if (user != null) {
			user.remove("password");
		}
	}

	/**
	 * 安全起见，去掉userList对应子集的map对象中的password属性
	 * 
	 * @param user
	 */
	public void removePasswordFromUser(List<Map<String, Object>> userList) {
		if (userList != null) {
			for (int i = 0; i < userList.size(); i++) {
				removePasswordFromUser(userList.get(i));
			}
		}
	}

	/**
	 * 判断是否含有敏感关键字
	 * 
	 * @param text
	 * @return true为含有关键字，false为正常
	 */
	public Boolean filterText(String text) {
		String key = "man_base_filter_str_group";
		if (Cache.get(key) == null) {
			synchronized (ManConstants.FIILTER_KEY_STR) {
				List<Map<String, Object>> filterList = filterService
						.queryListFromDbOrCache(
								"select * from man_base_filter", "240h");
				if (filterList != null && filterList.size() > 0) {
					StringBuilder stringBuilder = new StringBuilder();
					for (int i = 0; i < filterList.size(); i++) {
						stringBuilder.append(filterList.get(i).get("keystr")
								+ "|");
					}
					stringBuilder.deleteCharAt(stringBuilder.length() - 1);
					ManConstants.FIILTER_KEY_STR = stringBuilder.toString();
				}
				Cache.add(key, ManConstants.FIILTER_KEY_STR, "240h");
			}
		}
		if (ManConstants.FIILTER_KEY_STR == null) {
			ManConstants.FIILTER_KEY_STR = "";
		}
		Pattern pattern = Pattern.compile(ManConstants.FIILTER_KEY_STR);
		Matcher m = pattern.matcher(content);
		return m.matches();
	}

	/**
	 * 判断是否有关键字，并返回对应的json字符串
	 * 
	 * @param text
	 * @return
	 */
	public String checkTextByFilter(String text) {
		if (filterText(text)) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-104");
			jsonErrorResponse.setErrorMessage("抱歉，评论内容存在敏感字，请重新编辑");
			return renderJson(jsonErrorResponse);
		}
		return null;
	}

	/**
	 * 判断是否有用户id，并返回对应的json字符串
	 * 
	 * @return
	 */
	public String checkUserIdNull(Long uId) {
		if (uId == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-10011");
			jsonErrorResponse.setErrorMessage("抱歉，用户id参数为空，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		Map<String, Object> user = userService.queryOneRowFromDbOrCache(
				SqlUtils.genderQuerySql("man_view_baseuser_union", " userId = "
						+ uId, "*"), expire);
		if (user == null || user.size() == 0) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-32");
			jsonErrorResponse.setErrorMessage("抱歉，没有该用户的资料");
			return renderJson(jsonErrorResponse);
		}
		return null;
	}

	/**
	 * 判断是否有用户id，并返回对应的json字符串
	 * 
	 * @return
	 */
	public String checkUserIdNull() {
		return checkUserIdNull(userId);
	}

	/**
	 * 判断是否有献策的图片id，并返回对应的json字符串
	 * 
	 * @return
	 */
	public String checkAlbumImageIdNull() {
		if (imageId != null) {
			Map<String, Object> albumImage = imageService.queryById(imageId);
			if (albumImage == null || albumImage.size() == 0) {
				JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
				jsonErrorResponse.setErrorCode("-10042");
				jsonErrorResponse.setErrorMessage("抱歉，照片id参数非法，无法继续操作");
				return renderJson(jsonErrorResponse);
			}
		} else {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-10041");
			jsonErrorResponse.setErrorMessage("抱歉，照片id不能为空，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		return null;
	}

	/**
	 * 判断是否有文章id，并返回对应的json字符串
	 * 
	 * @return
	 */
	public String checkArticleIdNull() {
		if (articleId != null) {
			Map<String, Object> article = articleService.queryById(articleId);
			if (article == null || article.size() == 0) {
				JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
				jsonErrorResponse.setErrorCode("-10072");
				jsonErrorResponse.setErrorMessage("抱歉，文章id参数非法，无法继续操作");
				return renderJson(jsonErrorResponse);
			}
		} else {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-1071");
			jsonErrorResponse.setErrorMessage("抱歉，文章id为空不能为空，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		return null;
	}

	/**
	 * 判断是否有用户任务id，并返回对应的json字符串
	 * 
	 * @return
	 */
	public String checkUserQuestIdNull() {
		if (questId != null) {
			Map<String, Object> userQuest = userQuestService.queryById(questId);
			if (userQuest == null || userQuest.size() == 0) {
				JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
				jsonErrorResponse.setErrorCode("-10052");
				jsonErrorResponse.setErrorMessage("抱歉，用户任务id参数非法，无法继续操作");
				return renderJson(jsonErrorResponse);
			}
		} else {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-10051");
			jsonErrorResponse.setErrorMessage("抱歉，用户任务id不能为空，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		return null;
	}

	/**
	 * 将base64的字符串解析后写成图片,同时返回在本站的url地址
	 * 
	 * @param image
	 * @param userId
	 * @param fomart
	 * @return 返回空字符串的時候,代表写入异常或者传入的image为空字符串
	 */
	public String uploadBase64Img(String image, Long userId, String fomart) {
		if (StringUtils.isEmpty(image)) {
			return "";
		}
		byte[] imgByte = null;
		if (StringUtils.isEmpty(fomart)) {
			fomart = "jpg";
		}
		// TODO
		String fileName = new Date().getTime() + "-" + userId + "." + fomart;
		String extPath = MyDateUtils.parseDateToStr("yyyyMMdd") + "/"
				+ fileName;
		String filePath = SystemConstants.UPLOAD_SERVER_PATH + extPath;
		OutputStream os = null;
		try {
			imgByte = Base64.decode(image);
			File f = new File(filePath);
			// 如果文件不存在或者需要强制覆盖文件，则进行读取并写入
			if (!f.exists()) {
				File p = new File(f.getParent());
				if (!p.exists()) {
					p.mkdirs();
				}
				os = new FileOutputStream(new File(filePath));
				os.write(imgByte);
				// 这里调用，强制输出多个尺寸
				imageUtils.resetImgByWidth(filePath);
			}
		} catch (Exception e) {
			extPath = "";
			e.printStackTrace();
		} finally {
			try {
				os.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return extPath.equals("") ? "" : SystemConstants.UPLOAD_WEB_URL
				+ extPath;
	}

	/**
	 * 判断用户是否是装女郎
	 * 
	 * @param uId
	 * @return
	 */
	public String checkIsZhuangnvlang(Long uId) {
		Map<String, Object> user = userService.queryOneRowFromDbOrCache(
				SqlUtils.genderQuerySql("man_view_baseuser_union", " userId = "
						+ uId, "*"), expire);
		if (Integer.valueOf(user.get("gender") + "").intValue() != ManConstants.USER_GENDER_FEMALE
				.intValue()
				|| Integer.valueOf(user.get("groupId") + "").intValue() != ManConstants.USER_TYPE_ZHUANGNVLANG
						.intValue()) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-1091");
			jsonErrorResponse.setErrorMessage("抱歉，被投票对象不是女性或装女郎用户,无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		return null;
	}

	/**
	 * 判断用户的积分是否正常，且足够扣除
	 * 
	 * @param uId
	 * @param scoreNum
	 * @return
	 */
	public String checkUserScore(Long uId, Integer scoreNum) {
		if (score == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-1092");
			jsonErrorResponse.setErrorMessage("抱歉，积分不能为空,无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		Map<String, Object> user = userService.queryOneRow(SqlUtils
				.genderQuerySql("man_view_baseuser_union", " userId = " + uId,
						"*"));
		Integer userScore = Integer.valueOf(user.get("score") + "");
		if (userScore.intValue() < scoreNum.intValue()) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-1093");
			jsonErrorResponse.setErrorMessage("抱歉，您的积分不够赠送哦,请多多努力赚取积分");
			return renderJson(jsonErrorResponse);
		}
		return null;
	}

	/**
	 * 判断问题id是否为空,且有效
	 * 
	 * @return
	 */
	public String checkQuestionId() {
		if (questionId == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-10091");
			jsonErrorResponse.setErrorMessage("抱歉，问题id参数为空，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		Map<String, Object> question = questionService.queryById(questionId);
		if (question == null || question.size() == 0) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-10092");
			jsonErrorResponse.setErrorMessage("抱歉，问题id参数非法，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		return null;
	}

	/**
	 * 判断答案id是否为空,且有效
	 * 
	 * @return
	 */
	public String checkAnswerId() {
		if (answerId == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-10101");
			jsonErrorResponse.setErrorMessage("抱歉，答案id参数为空，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		Map<String, Object> answer = answerService.queryById(answerId);
		if (answer == null || answer.size() == 0) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-10102");
			jsonErrorResponse.setErrorMessage("抱歉，答案id参数非法，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		return null;
	}

	// TODO
	// action开始----------------------------------------------------------------------------//
	// GetGirlRank

	/**
	 * 获取应用最新版本号
	 */
	@Action(value = "/GetLastVersion", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String GetLastVersion() {
		Map<String, Object> version = versionService
				.queryOneRowFromDbOrCache(
						"select * from man_base_version order by createDate desc limit 0,1",
						expire);
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		jsonSuccessResponse.getData().put("version", version.get("version"));
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 支持/反对树洞回答
	 */
	@Action(value = "/SupportAnswer", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String SupportAnswer() {
		String checkUserId = checkUserIdNull();
		if (checkUserId != null) {
			return checkUserId;
		}
		String checkAnswerId = checkAnswerId();
		if (checkAnswerId != null) {
			return checkAnswerId;
		}
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("userId", userId);
		paramMap.put("answerId", answerId);
		paramMap.put("createDate",
				MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss"));
		// 操作类型（1.支持，-1.反对）
		if (valueNum.intValue() == 1) {
			paramMap.put("supportType", 0);
			answerService
					.update("update man_base_answer set supports = supports + 1,supportCount = supportCount + 1 where id = "
							+ answerId);
		}
		if (valueNum.intValue() == -1) {
			paramMap.put("supportType", 1);
			answerService
					.update("update man_base_answer set supports = supports - 1,opposeCount = opposeCount + 1 where id = "
							+ answerId);
		}
		answerSupportService.add(SqlUtils.genderInsertSql(
				"man_base_answer_support", paramMap));
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 发表树洞回答
	 */
	@Action(value = "/Answer", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String Answer() {
		String checkUserId = checkUserIdNull();
		if (checkUserId != null) {
			return checkUserId;
		}
		String checkQuestionId = checkQuestionId();
		if (checkQuestionId != null) {
			return checkQuestionId;
		}
		String checkText = checkTextByFilter(content);
		if (checkText != null) {
			return checkText;
		}
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("userId", userId);
		paramMap.put("content", content);
		paramMap.put("title", title);
		paramMap.put("questionId", questionId);
		paramMap.put("createDate",
				MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss"));
		answerId = answerService.add(SqlUtils.genderInsertSql(
				"man_base_answer", paramMap));
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		jsonSuccessResponse.getData().put("answerId", answerId);
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 获取树洞回答
	 */
	@Action(value = "/GetAnswer", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String GetAnswer() {
		if (pageNumber < 1) {
			pageNumber = 1;
		}
		if (pageLine < 0) {
			pageLine = ManConstants.COMMON_PAGE_SIZE;
		}
		String checkQuestionId = checkQuestionId();
		if (checkQuestionId != null) {
			return checkQuestionId;
		}
		String sql = "select a.*,u.name as userName,u.imageUrl as authorImageUrl from man_base_answer as a,man_view_baseuser_union as u where a.questionId = "
				+ questionId
				+ " and a.userId = u.userId limit  "
				+ ((pageNumber - 1) * pageLine) + "," + pageLine;
		List<Map<String, Object>> answerList = answerService
				.queryListFromDbOrCache(sql, expire);
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		jsonSuccessResponse.getData().put("answers", answerList);
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 发表树洞问题
	 */
	@Action(value = "/Question", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String Question() {
		String checkUserId = checkUserIdNull();
		if (checkUserId != null) {
			return checkUserId;
		}
		if (StringUtils.isEmpty(name)) {
			name = ManConstants.QUEST_COMMON_USERNAME;
		}
		String checkText = checkTextByFilter(content);
		if (checkText != null) {
			return checkText;
		}
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("userId", userId);
		paramMap.put("content", content);
		paramMap.put("title", title);
		paramMap.put("type", ManConstants.QUESTION_TYPE_SHUDONG);
		paramMap.put("userName", name);
		paramMap.put("createDate",
				MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss"));
		questionId = questionService.add(SqlUtils.genderInsertSql(
				"man_base_question", paramMap));
		userFieldService.update("update " + userFieldService.getTableName()
				+ " set questionCount = questionCount + 1 where userId = " + userId);
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		jsonSuccessResponse.getData().put("questionId", questionId);
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 获取树洞问题
	 */
	@Action(value = "/GetQuestion", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String GetQuestion() {
		if (pageNumber < 1) {
			pageNumber = 1;
		}
		if (pageLine < 0) {
			pageLine = ManConstants.COMMON_PAGE_SIZE;
		}

		// TODO 这里要修改的
		// String myQuestionSql =
		// "select q.*,a2.answers from man_base_question as q left join "
		// +
		// "(select count(*) as answers,a.questionId as questionId from man_base_answer as a group by a.questionId) as a2 "
		// + "on q.id = a2.questionId where q.type = "
		// + ManConstants.QUESTION_TYPE_SHUDONG
		// + (userId == null ? "" : " and q.userId = " + userId);
		// Page page = new Page(pageNumber, pageLine, myQuestionSql, expire,
		// questionService);
		// int totalCount = page.getTotalCount();
		// int totalPage = page.getTotalPage();
		// if(totalPage > )

		String sql = "select q.*,a2.answers from man_base_question as q left join "
				+ "(select count(*) as answers,a.questionId as questionId from man_base_answer as a group by a.questionId) as a2 "
				+ "on q.id = a2.questionId where q.type = "
				+ ManConstants.QUESTION_TYPE_SHUDONG
				+ " limit  "
				+ ((pageNumber - 1) * pageLine) + "," + pageLine;
		boolean needChangeNullCount = false;
		if (Cache.get(sql) == null) {
			needChangeNullCount = true;
		}
		List<Map<String, Object>> questionList = questionService
				.queryListFromDbOrCache(sql, expire);
		if (needChangeNullCount) {
			for (int i = 0; i < questionList.size(); i++) {
				Map<String, Object> question = questionList.get(i);
				Object count = question.get("answers");
				if (count == null) {
					question.put("answers", 0);
				}
			}
		}
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		jsonSuccessResponse.getData().put("questions", questionList);
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 赠送积分
	 */
	@Action(value = "/PresentScore", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String PresentScore() {
		String checkGirlId = checkUserIdNull(girlId);
		if (checkGirlId != null) {
			return checkGirlId;
		}
		String checkIsZhuangnvlang = checkIsZhuangnvlang(girlId);
		if (checkIsZhuangnvlang != null) {
			return checkIsZhuangnvlang;
		}
		String checkUserId = checkUserIdNull();
		if (checkUserId != null) {
			return checkUserId;
		}
		String checkUserScore = checkUserScore(userId, score);
		if (checkUserScore != null) {
			return checkUserScore;
		}
		if (scoreService.batchPresentScore(userId, girlId, score)) {
			JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
			return renderJson(jsonSuccessResponse);
		} else {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-1094");
			jsonErrorResponse.setErrorMessage("抱歉，出现异常，本次操作失败");
			return renderJson(jsonErrorResponse);
		}
	}

	/**
	 * 装女郎投票
	 */
	@Action(value = "/Vote", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String Vote() {
		String checkGirlId = checkUserIdNull(girlId);
		if (checkGirlId != null) {
			return checkGirlId;
		}
		String checkIsZhuangnvlang = checkIsZhuangnvlang(girlId);
		if (checkIsZhuangnvlang != null) {
			return checkIsZhuangnvlang;
		}
		String checkUserId = checkUserIdNull();
		if (checkUserId != null) {
			return checkUserId;
		}
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("userId", userId);
		paramMap.put("girlId", girlId);
		paramMap.put("createDate",
				MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss"));
		paramMap.put("createDay", MyDateUtils.parseDateToStr("yyyy-MM-dd"));
		voteService.add(SqlUtils.genderInsertSql("man_base_vote", paramMap));
		userService
				.update("update man_base_user_field set girlVoteCount = girlVoteCount + 1 where userId = "
						+ girlId);
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 获取装女郎匹配组
	 */
	@Action(value = "/GetGirlPK", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String GetGirlPK() {
		List<Map<String, Object>> tmpList = null;
		// 每次匹配2个装女郎
		int maxPkCount = 2;
		List<Map<String, Object>> girlPkList = new ArrayList<Map<String, Object>>();
		if (ManConstants.GIRL_PK_LIST == null
				|| ManConstants.GIRL_PK_LIST.size() < maxPkCount) {
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("state", ManConstants.USER_STATE_COMMON);
			paramMap.put("gender", ManConstants.USER_GENDER_FEMALE);
			paramMap.put("groupId", ManConstants.USER_TYPE_ZHUANGNVLANG);
			String sql = "select *,(girlPkCount * girlPkWeight) as pkNum from man_view_baseuser_union where "
					+ SqlUtils.genderConditionsByType(paramMap, "and")
					+ " order by pkNum desc";
			List<Map<String, Object>> cacheTmpList = userService.queryList(sql);
			removePasswordFromUser(cacheTmpList);
			if (tmpList == null) {
				tmpList = new ArrayList<Map<String, Object>>();
			}
			/**
			 * 功能描述： 获取显示在装女郎PK时的随机匹配组，系统随机匹配出两个装女郎，但是为了公平起见，随机匹配的有一个规则，
			 * 就是已匹配次数前10名的装女郎暂停匹配，匹配加权值的作用是让该装女郎的匹配次数减少一定数量，
			 * 从而让该装女郎出现更多的次数。加权值小于0时，则减少匹配次数，反之增加匹配次数。
			 */
			// 起始的索引值
			int start = 0;
			// 排除规则的排名靠前的数，即规则中的10
			int paimingNum = 10;
			int cacheTmpListSize = cacheTmpList.size();
			// 按照之前的规则,全部选出,平均分配,将会导致最早成为装女郎的匹配次数一直最多,无法达到最终的要求，所以考虑如下
			// 增加一个字段，每次匹配后，都会将匹配次数加1，在排序的时候，按此字段倒序，当总数超过12个（要考虑到用户量小的情况）时，剔除前10个人
			if (cacheTmpListSize >= paimingNum + maxPkCount) {
				start = 10;
			}
			for (int i = start; i < cacheTmpListSize; i++) {
				tmpList.add(cacheTmpList.get(i));
			}
			// 图片集合去掉了，改成了直接读取user对象中的imageUrl属性
			// for (int i = 0; i < tmpList.size(); i++) {
			// Map<String, Object> user = tmpList.get(i);
			// Long userIdTmp = (Long) user.get("id");
			// List<Map<String, Object>> albumsList = albumsService
			// .queryListFromDbOrCache(SqlUtils.genderQuerySql(
			// "man_base_albums", "userId = " + userIdTmp),
			// expire);
			// user.put("albums", albumsList);
			// for (Map<String, Object> albums : albumsList) {
			// Long albumsId = (Long) albums.get("id");
			// List<Map<String, Object>> albumsImagesList = albumsImageService
			// .queryListFromDbOrCache(SqlUtils.genderQuerySql(
			// "man_base_albums_image", "albumId = "
			// + albumsId + " and userId = "
			// + userIdTmp), expire);
			// albums.put("images", albumsImagesList);
			// }
			// }
		}
		if (ManConstants.GIRL_PK_LIST != null
				&& ManConstants.GIRL_PK_LIST.size() == 1) {
			addGirlPk(tmpList, girlPkList, 0);
		}
		if (ManConstants.GIRL_PK_LIST == null
				|| ManConstants.GIRL_PK_LIST.size() == 0) {
			ManConstants.GIRL_PK_LIST = tmpList;
		}
		int girlPkListSize = girlPkList.size();
		for (int i = 0; i < maxPkCount - girlPkListSize; i++) {
			int index = new Double(Math.random()
					* ManConstants.GIRL_PK_LIST.size()).intValue();
			if (girlPkList.size() == 1) {
				Map<String, Object> girl1 = girlPkList.get(0);
				Map<String, Object> girl2 = ManConstants.GIRL_PK_LIST
						.get(index);
				// 这里防止重复的记录
				while ((girl1.get("id") + "").equals(girl2.get("id") + "")) {
					index = new Double(Math.random()
							* ManConstants.GIRL_PK_LIST.size()).intValue();
					girl2 = ManConstants.GIRL_PK_LIST.get(index);
				}
				// TODO 这里做的测试用
				System.out.println(">>>> grilpk : " + girl1.get("id") + " vs "
						+ girl2.get("id"));
			}
			addGirlPk(tmpList, girlPkList, index);
		}
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		jsonSuccessResponse.getData().put("users", girlPkList);
		return renderJson(jsonSuccessResponse);
	}

	private void addGirlPk(List<Map<String, Object>> tmpList,
			List<Map<String, Object>> girlPkList, int index) {
		synchronized (ManConstants.GIRL_PK_LIST) {
			Map<String, Object> girl = ManConstants.GIRL_PK_LIST.get(index);
			// 这里给装女郎的匹配次数加1
			userService
					.update("update man_base_user_field set girlPkCount = girlPkCount + 1 where userId = "
							+ girl.get("id"));
			girlPkList.add(girl);
			ManConstants.GIRL_PK_LIST.remove(index);
		}
	}

	/**
	 * 装女郎资格申请
	 */
	@Action(value = "/ApplyGirl", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String ApplyGirl() {
		// System.out.println(paramMap);
		if (paramMap != null && paramMap.size() > 0) {
			if (image == null && paramMap.get("image") != null) {
				image = (String) paramMap.get("image");
			}
			if (icon == null && paramMap.get("icon") != null) {
				icon = (String) paramMap.get("icon");
			}
			if (userId == null && paramMap.get("userId") != null) {
				userId = Long.valueOf(paramMap.get("userId") + "");
			}
			if (age == null && paramMap.get("age") != null) {
				age = Integer.valueOf(paramMap.get("age") + "");
			}
			if (bwh == null && paramMap.get("bwh") != null) {
				bwh = (String) paramMap.get("bwh");
			}
			if (bust == null && paramMap.get("bust") != null) {
				bust = Integer.valueOf(paramMap.get("bust") + "");
			}
			if (waistline == null && paramMap.get("waistline") != null) {
				waistline = Integer.valueOf(paramMap.get("waistline") + "");
			}
			if (hip == null && paramMap.get("hip") != null) {
				hip = Integer.valueOf(paramMap.get("hip") + "");
			}
			if (constellation == null && paramMap.get("constellation") != null) {
				constellation = (String) paramMap.get("constellation");
			}
			if (girlCity == null && paramMap.get("girlCity") != null) {
				girlCity = (String) paramMap.get("girlCity");
			}
			if (birthday == null && paramMap.get("birthday") != null) {
				birthday = (String) paramMap.get("birthday");
			}
		}
		String checkUserId = checkUserIdNull();
		if (checkUserId != null) {
			return checkUserId;
		}
		if (age == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-1081");
			jsonErrorResponse.setErrorMessage("抱歉，年龄不能为空,无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		if (StringUtils.isEmpty(bwh)) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-1082");
			jsonErrorResponse.setErrorMessage("抱歉，三围不能为空,无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		if (StringUtils.isEmpty(constellation)) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-1083");
			jsonErrorResponse.setErrorMessage("抱歉，星座不能为空,无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		Map<String, Object> user = viewBaseuserUnionService
				.queryOneRow("select * from "
						+ viewBaseuserUnionService.getTableName()
						+ " where userId = " + userId + " limit 0,1");
		if (Integer.valueOf(user.get("gender") + "").intValue() != ManConstants.USER_GENDER_FEMALE
				.intValue()) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-1084");
			jsonErrorResponse.setErrorMessage("抱歉，您的资料中性别不是女性,无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		if (Integer.valueOf(user.get("groupId") + "").intValue() == ManConstants.USER_TYPE_ZHUANGNVLANG
				.intValue()
				|| Integer.valueOf(user.get("groupId") + "").intValue() == ManConstants.USER_TYPE_MINGREN
						.intValue()) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-1085");
			jsonErrorResponse.setErrorMessage("抱歉，您已是装女郎用户,无需申请");
			return renderJson(jsonErrorResponse);
		}
		List<Map<String, Object>> userApplyList = userApplyService
				.queryList("select * from man_base_user_apply where userId = "
						+ userId + " and state ="
						+ ManConstants.GIRL_APPLY_COMMON + "");
		if (userApplyList != null && userApplyList.size() > 0) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-1086");
			jsonErrorResponse.setErrorMessage("抱歉，已有您的装女郎用户申请记录,无需重复申请");
			return renderJson(jsonErrorResponse);
		}
		String iconUrl = uploadBase64Img(icon, userId, fomart);
		String imageUrl = uploadBase64Img(image, userId, fomart);
		// TODO 用户的类型是否在此时即进行切换，还未知
		Map<String, Object> params2 = new HashMap<String, Object>();
		params2.put("userId", userId);
		params2.put("createDate",
				MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss"));
		params2.put("name", user.get("name"));
		params2.put("girlCity", girlCity);
		params2.put("age", age);
		params2.put("bwh", bwh);
		params2.put("bust", bust);
		params2.put("waistline", waistline);
		params2.put("hip", hip);
		params2.put("constellation", constellation);
		params2.put("iconUrl", iconUrl);
		params2.put("imageUrl", imageUrl);
		params2.put("birthday", birthday);
		Long applyId = userApplyService.add(SqlUtils.genderInsertSql(
				"man_base_user_apply", params2));
		// TODO 这里将来要去掉
		applyUser(applyId);
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		return renderJson(jsonSuccessResponse);
	}

	private void applyUser(Long applyId) {
		try {
			Map<String, Object> userApply = userApplyService.queryById(applyId);
			Map<String, Object> params = new HashMap<String, Object>();
			Map<String, Object> params2 = new HashMap<String, Object>();
			params2.put("age", userApply.get("age"));
			params2.put("bust", userApply.get("bust"));
			params2.put("waistline", userApply.get("waistline"));
			params2.put("hip", userApply.get("hip"));
			params2.put("bwh", userApply.get("bwh"));
			params2.put("constellation", userApply.get("constellation"));
			params2.put("pkImageUrl", userApply.get("iconUrl"));
			params2.put("pkBigImageUrl", userApply.get("imageUrl"));
			params2.put("girlCity", userApply.get("girlCity"));
			params.put("groupId", ManConstants.USER_TYPE_ZHUANGNVLANG);

			userService.update(SqlUtils.genderUpdateSql("man_base_user",
					"userId = " + userApply.get("userId"),
					SqlUtils.genderConditionsByType(params, ",")));
			userFieldService.update(SqlUtils.genderUpdateSql(
					userFieldService.getTableName(),
					"userId = " + userApply.get("userId"),
					SqlUtils.genderConditionsByType(params2, ",")));
			Cache.removeKeyByContainStr("man_base_user");
			userApplyService.update("update man_base_user_apply set state = "
					+ ManConstants.GIRL_APPLY_OK + ",applyDate = '"
					+ MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss")
					+ "' where id = " + applyId);
			// TODO
			// 如果需要获取那些数据位0的装女郎到榜单中，给投票表中初始化一条为0的记录，投票人的id为-1这个特殊值，主要是方便获取相关的投票人信息
			Map<String, Object> params3 = new HashMap<String, Object>();
			params3.put("userId", 1);// 管理员的id
			params3.put("girlId", userApply.get("userId"));
			params3.put("createDate",
					MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss"));
			params3.put("voteNum", 0);
			params3.put("createDay", MyDateUtils.parseDateToStr("yyyy-MM-dd"));
			voteService.add(SqlUtils.genderInsertSql(
					voteService.getTableName(), params3));
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	/**
	 * 获取装女郎榜单
	 */
	@Action(value = "/GetGirlRank", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String GetGirlRank() {
		if (ManConstants.BANGDAN_TYPE_MAP.get(type) == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-1111");
			jsonErrorResponse.setErrorMessage("抱歉，榜单分类非法，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		if (days == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-1112");
			jsonErrorResponse.setErrorMessage("抱歉，统计天数不能为空，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		String sql = "";
		// 计算出多少天前对应的时间
		String startDate = MyDateUtils.parseDateToStr(
				MyDateUtils.addDate(-days), "yyyy-MM-dd");
		String addSql = " and voteDate >= '" + startDate + "'";
		// 按照作弊后的投票数计算投票热度
		if (type.intValue() == ManConstants.BANGDAN_TYPE_HOT.intValue()) {
			sql = "select *,sum(voteNum) as votes from man_view_bangdan where groupId = "
					+ ManConstants.USER_TYPE_ZHUANGNVLANG
					+ addSql
					+ " group by id order by votes desc";
		}
		if (type.intValue() == ManConstants.BANGDAN_TYPE_CITY.intValue()) {
			sql = "select *,sum(voteNum) as votes from man_view_bangdan where groupId = "
					+ ManConstants.USER_TYPE_ZHUANGNVLANG
					+ addSql
					+ " and girlCity = '"
					+ girlCity
					+ "' group by id order by votes desc";
		}
		if (type.intValue() == ManConstants.BANGDAN_TYPE_MINGREN.intValue()) {
			sql = "select *,sum(voteNum) as votes from man_view_bangdan where groupId = "
					+ ManConstants.USER_TYPE_MINGREN
					+ addSql
					+ " group by id order by votes desc";
		}
		List<Map<String, Object>> userList = viewBangdanService
				.queryListFromDbOrCache(sql, expire);
		removePasswordFromUser(userList);
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		jsonSuccessResponse.getData().put("users", userList);
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 举报文章
	 */
	@Action(value = "/AccusationArticle", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String AccusationArticle() {
		String checkUserId = checkUserIdNull();
		if (checkUserId != null) {
			return checkUserId;
		}
		String checkArticleIdNull = checkArticleIdNull();
		if (checkArticleIdNull != null) {
			return checkArticleIdNull;
		}
		if (StringUtils.isEmpty(content)) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-1071");
			jsonErrorResponse.setErrorMessage("抱歉，文章评论不能为空");
			return renderJson(jsonErrorResponse);
		}
		String checkText = checkTextByFilter(content);
		if (checkText != null) {
			return checkText;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userId", userId);
		params.put("articleId", articleId);
		params.put("content", content);
		params.put("createDate",
				MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss"));
		params.put("state", ManConstants.COMMENT_TYPE_COMMON);
		params.put("types", ManConstants.ARTICLE_COMMENT_TYPE_ACCUSATION);
		commentService
				.add(SqlUtils.genderInsertSql("man_base_comment", params));
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 赞文章
	 */
	@Action(value = "/Praise", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String Praise() {
		String checkUserId = checkUserIdNull();
		if (checkUserId != null) {
			return checkUserId;
		}
		String checkArticleIdNull = checkArticleIdNull();
		if (checkArticleIdNull != null) {
			return checkArticleIdNull;
		}
		if (StringUtils.isEmpty(content)) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-1071");
			jsonErrorResponse.setErrorMessage("抱歉，文章评论不能为空");
			return renderJson(jsonErrorResponse);
		}
		String checkText = checkTextByFilter(content);
		if (checkText != null) {
			return checkText;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userId", userId);
		params.put("articleId", articleId);
		params.put("content", content);
		params.put("createDate",
				MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss"));
		params.put("state", ManConstants.COMMENT_TYPE_COMMON);
		params.put("types", ManConstants.ARTICLE_COMMENT_TYPE_PRAISE);
		commentService
				.add(SqlUtils.genderInsertSql("man_base_comment", params));
		articleService.update("update man_base_article set hots = hots + "
				+ ManConstants.HOTS_ADD_PRAISE
				+ " , praise = praise + 1 where id = " + articleId);
		userFieldService.update("update " + userFieldService.getTableName()
				+ " set likesCount = likesCount + 1 where userId = " + userId);
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 评论文章
	 */
	@Action(value = "/CommentArticle", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String CommentArticle() {
		String checkUserId = checkUserIdNull();
		if (checkUserId != null) {
			return checkUserId;
		}
		String checkArticleIdNull = checkArticleIdNull();
		if (checkArticleIdNull != null) {
			return checkArticleIdNull;
		}
		if (StringUtils.isEmpty(content)) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-1071");
			jsonErrorResponse.setErrorMessage("抱歉，文章评论不能为空");
			return renderJson(jsonErrorResponse);
		}
		String checkText = checkTextByFilter(content);
		if (checkText != null) {
			return checkText;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userId", userId);
		params.put("articleId", articleId);
		params.put("content", content);
		params.put("createDate",
				MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss"));
		// TODO 上线后要改回来，现在为了满足测试手机接口的需求
		// params.put("state", ManConstants.COMMENT_TYPE_COMMON);
		params.put("state", ManConstants.COMMENT_TYPE_AUDITED);
		params.put("types", ManConstants.ARTICLE_COMMENT_TYPE_COMMENT);
		commentService
				.add(SqlUtils.genderInsertSql("man_base_comment", params));
		articleService.update("update man_base_article set hots = hots + "
				+ ManConstants.HOTS_ADD_COMMENT
				+ " , comments = comments + 1 where id = " + articleId);
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 获取评论
	 */
	@Action(value = "/GetComment", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String GetComment() {
		if (pageNumber < 1) {
			pageNumber = 1;
		}
		if (pageLine < 0) {
			pageLine = ManConstants.COMMON_PAGE_SIZE;
		}
		if (articleId == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-92");
			jsonErrorResponse.setErrorMessage("抱歉，文章id为空");
			return renderJson(jsonErrorResponse);
		}
		List<Map<String, Object>> commentList = commentService
				.queryListFromDbOrCache(
						"select c.*,u.`name` as userName from man_base_comment c , man_view_baseuser_union u where c.userId = u.userId and c.types = "
								+ ManConstants.ARTICLE_COMMENT_TYPE_COMMENT
								+ " and c.state = "
								+ ManConstants.COMMENT_STATE_SUCCESS
								+ " and c.articleId = "
								+ articleId
								+ "  order by c.createDate desc limit "
								+ ((pageNumber - 1) * pageLine)
								+ ","
								+ pageLine, expire);
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		jsonSuccessResponse.getData().put("comments", commentList);
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 取消收藏文章
	 */
	@Action(value = "/UnFavorite", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String UnFavorite() {
		String checkUserId = checkUserIdNull();
		if (checkUserId != null) {
			return checkUserId;
		}
		if (articleId == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-82");
			jsonErrorResponse.setErrorMessage("抱歉，被收藏、取消收藏文章id为空");
			return renderJson(jsonErrorResponse);
		}
		if (getValue() == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-83");
			jsonErrorResponse.setErrorMessage("抱歉，是否收藏选项不能为空");
			return renderJson(jsonErrorResponse);
		}
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("userId", userId);
		paramMap.put("articleId", articleId);
		if (getValue()) {
			Map<String, Object> article = articleCollectionService
					.queryOneRow(SqlUtils.genderQuerySql(
							"man_base_article_collection",
							SqlUtils.genderConditionsByType(paramMap, "and")));
			if (article != null && article.size() > 0) {
				JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
				jsonErrorResponse.setErrorCode("-84");
				jsonErrorResponse.setErrorMessage("抱歉，您已收藏该文章，请不要重复收藏");
				return renderJson(jsonErrorResponse);
			}
			paramMap.put("createDate",
					MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss"));
			articleCollectionService.add(SqlUtils.genderInsertSql(
					"man_base_article_collection", paramMap));
			articleService.update("update man_base_article set hots = hots + "
					+ ManConstants.HOTS_ADD_FAVORITE
					+ " , collect = collect + 1 where id = " + articleId);
			userFieldService
					.update("update "
							+ userFieldService.getTableName()
							+ " set collectionCount = collectionCount + 1 where userId = "
							+ userId);
		} else {
			Map<String, Object> article = articleCollectionService
					.queryOneRow(SqlUtils.genderQuerySql(
							"man_base_article_collection",
							SqlUtils.genderConditionsByType(paramMap, "and")));
			if (article != null && article.size() > 0) {
				articleCollectionService
						.excute("delete from man_base_article_collection where userId = "
								+ userId + " and articleId = " + articleId);
				articleService
						.update("update man_base_article set hots = hots - "
								+ ManConstants.HOTS_ADD_FAVORITE
								+ " , collect = collect - 1 where id = "
								+ articleId);
				userFieldService
						.update("update "
								+ userFieldService.getTableName()
								+ " set collectionCount = collectionCount - 1 where userId = "
								+ userId);
			} else {
				JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
				jsonErrorResponse.setErrorCode("-85");
				jsonErrorResponse.setErrorMessage("抱歉，您已取消收藏该文章，请不要重复取消收藏");
				return renderJson(jsonErrorResponse);
			}

		}
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 收藏收藏文章
	 */
	@Action(value = "/Favorite", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String Favorite() {
		String checkUserId = checkUserIdNull();
		if (checkUserId != null) {
			return checkUserId;
		}
		if (articleId == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-82");
			jsonErrorResponse.setErrorMessage("抱歉，被收藏、取消收藏文章id为空");
			return renderJson(jsonErrorResponse);
		}
		if (getValue() == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-83");
			jsonErrorResponse.setErrorMessage("抱歉，是否收藏选项不能为空");
			return renderJson(jsonErrorResponse);
		}
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("userId", userId);
		paramMap.put("articleId", articleId);
		if (getValue()) {
			Map<String, Object> article = articleCollectionService
					.queryOneRow(SqlUtils.genderQuerySql(
							"man_base_article_collection",
							SqlUtils.genderConditionsByType(paramMap, "and")));
			if (article != null && article.size() > 0) {
				JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
				jsonErrorResponse.setErrorCode("-84");
				jsonErrorResponse.setErrorMessage("抱歉，您已收藏该文章，请不要重复收藏");
				return renderJson(jsonErrorResponse);
			}
			paramMap.put("createDate",
					MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss"));
			articleCollectionService.add(SqlUtils.genderInsertSql(
					"man_base_article_collection", paramMap));
			articleService.update("update man_base_article set hots = hots + "
					+ ManConstants.HOTS_ADD_FAVORITE
					+ " , collect = collect + 1 where id = " + articleId);
			userFieldService
					.update("update "
							+ userFieldService.getTableName()
							+ " set collectionCount = collectionCount + 1 where userId = "
							+ userId);
		} else {
			Map<String, Object> article = articleCollectionService
					.queryOneRow(SqlUtils.genderQuerySql(
							"man_base_article_collection",
							SqlUtils.genderConditionsByType(paramMap, "and")));
			if (article != null && article.size() > 0) {
				articleCollectionService
						.excute("delete from man_base_article_collection where userId = "
								+ userId + " and articleId = " + articleId);
				articleService
						.update("update man_base_article set hots = hots - "
								+ ManConstants.HOTS_ADD_FAVORITE
								+ " , collect = collect - 1 where id = "
								+ articleId);
				userFieldService
						.update("update "
								+ userFieldService.getTableName()
								+ " set collectionCount = collectionCount - 1 where userId = "
								+ userId);
			} else {
				JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
				jsonErrorResponse.setErrorCode("-85");
				jsonErrorResponse.setErrorMessage("抱歉，您已取消收藏该文章，请不要重复取消收藏");
				return renderJson(jsonErrorResponse);
			}

		}
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 手机上搜索文章
	 */
	@Action(value = "/SearchArticle", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String SearchArticle() {
		String sqls = "select a.*,u.name as userName,u.imageUrl as authorImageUrl from man_view_basearticle_union as a,man_view_baseuser_union as u "
				+ "where a.authorId = u.userId and (a.summary like '%"
				+ keyword
				+ "%' or u.name like '%"
				+ keyword
				+ "%') and a.state = "
				+ ManConstants.ARTICLE_STATE_UP
				+ " order by a.top_time desc ,a.createDate desc";
		Page page = new Page(pageNumber, pageLine, sqls, expire, articleService);
		List<Map<String, Object>> artileList = page.getList();
		for (int i = 0; i < artileList.size(); i++) {
			Map<String, Object> article = artileList.get(i);
			List<Map<String, Object>> articleImageList = imageService
					.queryListFromDbOrCache(
							SqlUtils.genderQuerySql(
									imageService.getTableName(), "articleId = "
											+ article.get("id"))
									+ " order by createDate desc", expire);
			article.put("images", articleImageList);
		}
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		jsonSuccessResponse.getData().put("articles", artileList);
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 手机上发文章
	 */
	@Action(value = "/WriteArticle", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String WriteArticle() {
		if (paramMap != null && paramMap.size() > 0) {
			if (userId == null && paramMap.get("userId") != null) {
				userId = Long.valueOf(paramMap.get("userId") + "");
			}
			if (images == null && paramMap.get("images") != null) {
				// try {
				// String[] tmp = (String[]) paramMap.get("images");
				// images = new ArrayList<Map<String, Object>>();
				// for (int i = 0; i < tmp.length; i++) {
				// String tmpStr = tmp[i];
				// tmpStr.replaceAll("(", "").replaceAll(")", "")
				// .replaceAll(";", "")
				// .replaceAll("image =", "\"image\" : ");
				// System.out.println(">>>>>>>  " + tmpStr);
				// images.add((Map<String, Object>) Json.fromJson(tmpStr));
				// }
				// } catch (Exception e0) {
				// e0.printStackTrace();
				try {
					images = (List<Map<String, Object>>) paramMap.get("images");
				} catch (Exception e) {
					e.printStackTrace();
					try {
						images = (List<Map<String, Object>>) Json
								.fromJson(paramMap.get("images") + "");
					} catch (Exception e2) {
						e2.printStackTrace();
						try {
							Map<String, Object>[] tmp = (Map<String, Object>[]) Json
									.fromJson(paramMap.get("images") + "");
							images = new ArrayList<Map<String, Object>>();
							for (int i = 0; i < tmp.length; i++) {
								images.add(tmp[i]);
							}
						} catch (Exception e3) {
							e3.printStackTrace();
							try {
								Map<String, Object>[] tmp = (Map<String, Object>[]) paramMap
										.get("images");
								images = new ArrayList<Map<String, Object>>();
								for (int i = 0; i < tmp.length; i++) {
									images.add(tmp[i]);
								}
							} catch (Exception e4) {
								e4.printStackTrace();
							}
						}
					}
				}
				// }
			}
			if (title == null && paramMap.get("title") != null) {
				title = (String) paramMap.get("title");
			}
			if (summary == null && paramMap.get("summary") != null) {
				summary = (String) paramMap.get("summary");
			}
		}
		images = (List<Map<String, Object>>) paramMap.get("images");
		String now = MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss");
		Map<String, Object> paramMap = new HashMap<String, Object>();
		Map<String, Object> paramMap3 = new HashMap<String, Object>();
		paramMap.put("title", title);
		paramMap.put("authorId", userId);
		Map<String, Object> user = viewBaseuserUnionService
				.queryOneRow("select * from "
						+ viewBaseuserUnionService.getTableName()
						+ " where userId = " + userId + " limit 0,1");
		Integer userType = Integer.valueOf(user.get("groupId") + "");
		if (ManConstants.ARTICLE_PUBLISHTYPE_MAP.get(userType) == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-10061");
			jsonErrorResponse.setErrorMessage("抱歉，当前用户类型不满足发布文章条件，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		paramMap3.put("author_type", userType);
		paramMap.put("state", ManConstants.ARTICLE_STATE_COMMON);
		paramMap.put("createDate", now);
		paramMap.put("update_time", now);
		paramMap.put("summary", summary);
		paramMap3.put("publish_type", userType);
		articleId = articleService.add(SqlUtils.genderInsertSql(
				"man_base_article", paramMap));
		paramMap3.put("id", articleId);
		articleFieldService.add(SqlUtils.genderInsertSql(
				"man_base_article_field", paramMap3));
		userFieldService.update("update " + userFieldService.getTableName()
				+ " set articleCount = articleCount + 1 where userId = "
				+ userId);

		if (images != null && images.size() > 0) {
			for (int i = 0; i < images.size(); i++) {
				byte[] imgByte = null;
				if (StringUtils.isEmpty(fomart)) {
					fomart = "jpg";
				}
				Map<String, Object> image = images.get(i);
				// TODO
				String fileName = new Date().getTime() + "-" + userId + "."
						+ fomart;
				String extPath = MyDateUtils.parseDateToStr("yyyyMMdd") + "/"
						+ fileName;
				String filePath = SystemConstants.UPLOAD_SERVER_PATH + extPath;
				OutputStream os = null;
				try {
					imgByte = Base64.decode(image.get("image") + "");
					File f = new File(filePath);
					// 如果文件不存在或者需要强制覆盖文件，则进行读取并写入
					if (!f.exists()) {
						File p = new File(f.getParent());
						if (!p.exists()) {
							p.mkdirs();
						}
						os = new FileOutputStream(new File(filePath));
						os.write(imgByte);
						// 这里调用，强制输出多个尺寸
						imageUtils.resetImgByWidth(filePath);
						Map<String, Object> paramMap2 = new HashMap<String, Object>();
						paramMap2.put("articleId", articleId);
						paramMap2.put("imageUrl",
								SystemConstants.UPLOAD_WEB_URL + extPath);
						paramMap2.put("summary", summary);
						paramMap2.put("createDate", now);
						paramMap2.put("userId", userId);
						imageService.add(SqlUtils.genderInsertSql(
								imageService.getTableName(), paramMap2));
					}
				} catch (Exception e) {
					e.printStackTrace();
					JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
					jsonErrorResponse.setErrorCode("-63");
					jsonErrorResponse
							.setErrorMessage("抱歉，base64转换错误，请重新尝试，保存失败");
					return renderJson(jsonErrorResponse);
				} finally {
					try {
						os.close();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}
		// TODO 临时增加的文章上线
		upArticle(articleId);

		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		return renderJson(jsonSuccessResponse);
	}

	private void upArticle(Long articleId) {
		// TODO Auto-generated method stub
		try {
			String now = MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss");
			Map<String, Object> paramMap = new HashMap<String, Object>();
			Map<String, Object> paramMap2 = new HashMap<String, Object>();
			paramMap.put("state", ManConstants.ARTICLE_STATE_UP);
			paramMap2.put("audit_id", 2);
			paramMap2.put("audit_time", now);
			paramMap.put("publish_time", now);
			articleService.update(SqlUtils.genderUpdateSql("man_base_article",
					"id = " + articleId,
					SqlUtils.genderConditionsByType(paramMap, ",")));
			articleFieldService.update(SqlUtils.genderUpdateSql(
					articleFieldService.getTableName(), "id = " + articleId,
					SqlUtils.genderConditionsByType(paramMap2, ",")));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 获取文章
	 */
	@Action(value = "/GetArticle", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String GetArticle() {
		if (pageNumber < -1) {
			pageNumber = 1;
		}
		if (pageLine < 0) {
			pageLine = ManConstants.COMMON_PAGE_SIZE;
		}
		// and a.columnId = "
		// + columnId
		// + "
		int maxHots = 50;
		int minSize = 15;
		// ------>获取文章列表，获取所有顶置文章+热门文章+关注用户发表的文章，按时间倒序。热门文章是指热度超过50的文章（热度50以上文章不满15条则不限热度，至少返回15条记录）
		// 先根据规则获取相关的记录
		String appendSql = "";
		if (pageNumber.intValue() > 0) {
			appendSql = " LIMIT " + ((pageNumber - 1) * pageLine) + ","
					+ pageLine;
		}
		String sql = "select u2.*,u.`name` as userName,u.imageUrl as authorImageUrl from (SELECT a.* FROM man_view_basearticle_union a WHERE "
				+ "a.authorId IN( SELECT b.followUserId FROM man_base_user_attention b WHERE b.userId = "
				+ userId
				+ " ) OR a.top_time IS NOT NULL or a.hots > "
				+ maxHots
				+ " ORDER BY a.top_time DESC, a.createDate DESC, a.hots DESC"
				+ appendSql
				+ ") as u2,man_view_baseuser_union u where u2.authorId = u.userId and u2.state = "
				+ ManConstants.ARTICLE_STATE_UP;
		List<Map<String, Object>> artileList = articleService.queryList(sql);
		// 如果不满足15条，则进行补全
		int artileListSize = artileList.size();
		if (pageNumber.intValue() == 1 && artileListSize < minSize) {
			StringBuilder sb = new StringBuilder("(");
			for (int i = 0; i < artileListSize; i++) {
				sb.append(artileList.get(i).get("id"));
				if (i < artileListSize - 1) {
					sb.append(",");
				}
			}
			sb.append(")");
			List<Map<String, Object>> artileList2 = articleService
					.queryList("select a.*,u.`name` as userName from man_view_basearticle_union a,man_view_baseuser_union u where a.authorId = u.userId and a.state = "
							+ ManConstants.ARTICLE_STATE_UP
							+ " and a.id not in "
							+ sb.toString()
							+ "  order by a.top_time desc,a.hots desc,a.createDate desc limit "
							+ 0 + "," + (minSize - artileListSize));
			artileList.addAll(artileList2);
		}
		for (int i = 0; i < artileList.size(); i++) {
			Map<String, Object> article = artileList.get(i);
			List<Map<String, Object>> articleImageList = imageService
					.queryListFromDbOrCache(
							SqlUtils.genderQuerySql(
									imageService.getTableName(), "articleId = "
											+ article.get("id"))
									+ " order by createDate desc", expire);
			article.put("images", articleImageList);
		}
		addArticleAttentionAndCollect(artileList);
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		jsonSuccessResponse.getData().put("articles", artileList);
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 增加文章是否被当前用户收藏，文章作者是否被当前用户关注
	 * 
	 * @param artileList
	 */
	private void addArticleAttentionAndCollect(
			List<Map<String, Object>> artileList) {
		// TODO文章需要增加关注和收藏属性的时候调用
		if (artileList != null && artileList.size() > 0) {
			for (Map<String, Object> article : artileList) {
				Long articleId = Long.valueOf(article.get("id") + "");
				Long authorId = Long.valueOf(article.get("authorId") + "");

				article.put("isAttention", isAttention(curUserId, authorId));
				article.put("isCollect", isCollect(articleId, curUserId));
			}
		}
	}

	private boolean isCollect(Long articleId, Long curUserId) {
		if (curUserId == null || articleId == null) {
			return false;
		}
		Map<String, Object> params2 = new HashMap<String, Object>();
		params2.put("articleId", articleId);
		params2.put("userId", curUserId);
		Map<String, Object> collect = articleCollectionService
				.queryOneRowFromDbOrCache("select id from "
						+ articleCollectionService.getTableName()
						+ " where  articleId = " + articleId + " and userId = "
						+ curUserId, expire);
		return collect != null && collect.size() > 0;
	}

	private boolean isSigned(Long curUserId, Long userId) {
		if (curUserId == null || userId == null) {
			return false;
		}
		if (curUserId.longValue() != userId.longValue()) {
			return false;
		}
		Map<String, Object> params1 = new HashMap<String, Object>();
		params1.put("userId", curUserId);
		params1.put("signTime < ", MyDateUtils.parseDateToStr(
				MyDateUtils.addDate(1), "yyyy-MM-dd"));
		params1.put("signTime >= ", MyDateUtils.parseDateToStr("yyyy-MM-dd"));
		Map<String, Object> signed = userSignService.queryOneRowFromDbOrCache(
				SqlUtils.genderQuerySql(userSignService.getTableName(),
						SqlUtils.genderConditionsByType(params1, "and")),
				expire);
		return signed != null && signed.size() > 0;
	}

	private boolean isAttention(Long curUserId, Long authorId) {
		if (curUserId == null || authorId == null) {
			return false;
		}
		Map<String, Object> params1 = new HashMap<String, Object>();
		params1.put("userId", curUserId);
		params1.put("followUserId", authorId);
		Map<String, Object> attention = userAttentionService
				.queryOneRowFromDbOrCache("select id from "
						+ userAttentionService.getTableName()
						+ " where  followUserId = " + authorId
						+ " and userId = " + curUserId, expire);
		return attention != null && attention.size() > 0;
	}

	/**
	 * 获取FM节目单
	 */
	@SuppressWarnings("unchecked")
	@Action(value = "/GetFM", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String GetFM() {
		List<Map<String, Object>> fmList = fmService.queryListFromDbOrCache(
				SqlUtils.genderQuerySql("man_base_fm",
						"state = 1 order by top_time desc,createDate desc"),
				expire);
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		jsonSuccessResponse.getData().put("channels", fmList);
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 领取任务奖励
	 */
	@Action(value = "/RewardQuest", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String RewardQuest() {
		String checkUserId = checkUserIdNull();
		if (checkUserId != null) {
			return checkUserId;
		}
		String checkUserQuestId = checkUserQuestIdNull();
		if (checkUserQuestId != null) {
			return checkUserQuestId;
		}
		Map<String, Object> userQuest = userQuestService
				.queryOneRow("select u.*,q.scoreRuleId as scoreRuleId from man_base_user_quest as u,man_base_quest as q where q.id = u.questId and u.id = "
						+ questId);
		if (!(userQuest.get("needStep") + "").equals(userQuest
				.get("currentStep") + "")) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-10054");
			jsonErrorResponse.setErrorMessage("抱歉，用户任务还未完成，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		scoreService.addScore(userId,
				Integer.valueOf(userQuest.get("score") + ""),
				Long.valueOf(userQuest.get("scoreRuleId") + ""));
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 提交任务
	 */
	@Action(value = "/CommitQuest", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String CommitQuest() {
		String checkUserId = checkUserIdNull();
		if (checkUserId != null) {
			return checkUserId;
		}
		String checkUserQuestId = checkUserQuestIdNull();
		if (checkUserQuestId != null) {
			return checkUserQuestId;
		}
		Map<String, Object> userQuest = userQuestService.queryById(questId);
		if ((userQuest.get("needStep") + "").equals(userQuest
				.get("currentStep") + "")) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-10053");
			jsonErrorResponse.setErrorMessage("抱歉，用户任务已完成，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		userQuestService
				.update("update man_base_user_quest set currentStep = currentStep + 1 where id = "
						+ questId);
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		jsonSuccessResponse.getData().put("completed", true);
		jsonSuccessResponse.getData().put("currentStep",
				Integer.valueOf(userQuest.get("currentStep") + "") + 1);
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 获取用户任务
	 */
	@Action(value = "/GetQuest", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String GetQuest() {
		String checkUserId = checkUserIdNull();
		if (checkUserId != null) {
			return checkUserId;
		}
		Map<String, Object> user = userService.queryOneRowFromDbOrCache(
				SqlUtils.genderQuerySql("man_view_baseuser_union", " userId = "
						+ userId, "*"), expire);
		Map<String, Object> paramMap2 = new HashMap<String, Object>();
		String today = MyDateUtils.parseDateToStr("yyyy-MM-dd");
		String nextday = MyDateUtils.parseDateToStr(MyDateUtils.addDate(1),
				"yyyy-MM-dd");
		paramMap2.put("userId", userId);
		paramMap2.put("createDate >=", today);
		paramMap2.put("createDate <", nextday);
		List<Map<String, Object>> userQuestList = userQuestService
				.queryList(SqlUtils.genderQuerySql("man_base_user_quest",
						SqlUtils.genderConditionsByType(paramMap2, "and")));
		// 如果用户的任务列表中没有当天记录，则进行创建
		if (userQuestList == null || userQuestList.size() == 0) {
			List<Map<String, Object>> questList = questionService
					.queryList("select * from man_base_quest where questUserType in ('"
							+ ManConstants.QUEST_TYPE_ALL
							+ "','"
							+ ManConstants.QUEST_TYPE_USERTYPE
							+ "_"
							+ user.get("groupId")
							+ "','"
							+ ManConstants.QUEST_TYPE_GENDER
							+ "_"
							+ user.get("gender") + "')");
			for (int i = 0; i < questList.size(); i++) {
				Map<String, Object> questTmp = questList.get(i);
				Map<String, Object> params = new HashMap<String, Object>();
				params.put("questId", questTmp.get("id"));
				params.put("type", questTmp.get("questSiteType"));
				params.put("title", questTmp.get("questName"));
				params.put("summary", questTmp.get("questDesc"));
				params.put("needStep", questTmp.get("questProcessCount"));
				params.put("currentStep", 0);
				params.put("score", questTmp.get("score"));
				params.put("createDate",
						MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss"));
				params.put("userId", userId);
				userQuestService.add(SqlUtils.genderInsertSql(
						"man_base_user_quest", params));
			}
			userQuestList = userQuestService.queryList(SqlUtils.genderQuerySql(
					"man_base_user_quest",
					SqlUtils.genderConditionsByType(paramMap2, "and")));
		}
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		jsonSuccessResponse.getData().put("quests", userQuestList);
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 取消关注用户
	 */
	@Action(value = "/UnFollowUser", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String UnFollowUser() {
		String checkUserId = checkUserIdNull();
		if (checkUserId != null) {
			return checkUserId;
		}
		if (followUserId == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-72");
			jsonErrorResponse.setErrorMessage("抱歉，被关注、取消关注用户id为空");
			return renderJson(jsonErrorResponse);
		}
		if (getValue() == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-73");
			jsonErrorResponse.setErrorMessage("抱歉，是否关注选项不能为空");
			return renderJson(jsonErrorResponse);
		}
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("userId", userId);
		paramMap.put("followUserId", followUserId);
		if (getValue()) {
			paramMap.put("type", ManConstants.ATTENTION_TYPE_COMMON);
			Map<String, Object> tmp = userAttentionService.queryOneRow(SqlUtils
					.genderQuerySql("man_base_user_attention",
							SqlUtils.genderConditionsByType(paramMap, "and")));
			if (tmp != null && tmp.size() > 0) {
				JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
				jsonErrorResponse.setErrorCode("-74");
				jsonErrorResponse.setErrorMessage("您已关注该用户，无需重复关注");
				return renderJson(jsonErrorResponse);
			}
			paramMap.put("createDate",
					MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss"));
			userAttentionService.add(SqlUtils.genderInsertSql(
					"man_base_user_attention", paramMap));
			userFieldService
					.update("update "
							+ userFieldService.getTableName()
							+ " set attentionCount = attentionCount + 1 where userId = "
							+ userId);
			userFieldService
					.update("update "
							+ userFieldService.getTableName()
							+ " set isAttentionCount = isAttentionCount + 1 where userId = "
							+ followUserId);
		} else {
			userAttentionService
					.excute("delete from man_base_user_attention where userId = "
							+ userId + " and followUserId = " + followUserId);
			userFieldService
					.update("update "
							+ userFieldService.getTableName()
							+ " set attentionCount = attentionCount - 1 where userId = "
							+ userId);
			userFieldService
					.update("update "
							+ userFieldService.getTableName()
							+ " set isAttentionCount = isAttentionCount - 1 where userId = "
							+ followUserId);
		}
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 关注关注用户
	 */
	@Action(value = "/FollowUser", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String FollowUser() {
		String checkUserId = checkUserIdNull();
		if (checkUserId != null) {
			return checkUserId;
		}
		if (followUserId == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-72");
			jsonErrorResponse.setErrorMessage("抱歉，被关注、取消关注用户id为空");
			return renderJson(jsonErrorResponse);
		}
		if (getValue() == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-73");
			jsonErrorResponse.setErrorMessage("抱歉，是否关注选项不能为空");
			return renderJson(jsonErrorResponse);
		}
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("userId", userId);
		paramMap.put("followUserId", followUserId);
		if (getValue()) {
			paramMap.put("type", ManConstants.ATTENTION_TYPE_COMMON);
			Map<String, Object> tmp = userAttentionService.queryOneRow(SqlUtils
					.genderQuerySql("man_base_user_attention",
							SqlUtils.genderConditionsByType(paramMap, "and")));
			if (tmp != null && tmp.size() > 0) {
				JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
				jsonErrorResponse.setErrorCode("-74");
				jsonErrorResponse.setErrorMessage("您已关注该用户，无需重复关注");
				return renderJson(jsonErrorResponse);
			}
			paramMap.put("createDate",
					MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss"));
			userAttentionService.add(SqlUtils.genderInsertSql(
					"man_base_user_attention", paramMap));
			userFieldService
					.update("update "
							+ userFieldService.getTableName()
							+ " set attentionCount = attentionCount + 1 where userId = "
							+ userId);
			userFieldService
					.update("update "
							+ userFieldService.getTableName()
							+ " set isAttentionCount = isAttentionCount + 1 where userId = "
							+ followUserId);
		} else {
			userAttentionService
					.excute("delete from man_base_user_attention where userId = "
							+ userId + " and followUserId = " + followUserId);
			userFieldService
					.update("update "
							+ userFieldService.getTableName()
							+ " set attentionCount = attentionCount - 1 where userId = "
							+ userId);
			userFieldService
					.update("update "
							+ userFieldService.getTableName()
							+ " set isAttentionCount = isAttentionCount - 1 where userId = "
							+ followUserId);
		}
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 举报照片
	 */
	@Action(value = "/ReportImage", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String ReportImage() {
		String checkUserId = checkUserIdNull();
		if (checkUserId != null) {
			return checkUserId;
		}
		String checkAlbumImageId = checkAlbumImageIdNull();
		if (checkAlbumImageId != null) {
			return checkAlbumImageId;
		}
		String checkText = checkTextByFilter(content);
		if (checkText != null) {
			return checkText;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("imageId", imageId);
		params.put("userId", userId);
		params.put("content", content);
		params.put("type", ManConstants.ALBUMIMAGE_COMMENT_TYPE_JUBAO);
		params.put("createDate",
				MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss"));
		albumsImageCommentService.add(SqlUtils.genderInsertSql(
				"man_base_albums_image_comment", params));
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 评论照片
	 */
	@Action(value = "/CommentImage", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String CommentImage() {
		String checkUserId = checkUserIdNull();
		if (checkUserId != null) {
			return checkUserId;
		}
		String checkAlbumImageId = checkAlbumImageIdNull();
		if (checkAlbumImageId != null) {
			return checkAlbumImageId;
		}
		String checkText = checkTextByFilter(content);
		if (checkText != null) {
			return checkText;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("imageId", imageId);
		params.put("userId", userId);
		params.put("content", content);
		params.put("type", ManConstants.ALBUMIMAGE_COMMENT_TYPE_COMMENT);
		params.put("createDate",
				MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss"));
		albumsImageCommentService.add(SqlUtils.genderInsertSql(
				"man_base_albums_image_comment", params));
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 删除照片
	 */
	@Action(value = "/RemoveImage", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String RemoveImage() {
		if (imageId != null) {
			Map<String, Object> albumImage = imageService.queryById(imageId);
			if (albumImage == null || albumImage.size() == 0) {
				JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
				jsonErrorResponse.setErrorCode("-10042");
				jsonErrorResponse.setErrorMessage("抱歉，照片id参数非法，无法继续操作");
				return renderJson(jsonErrorResponse);
			}
			imageService.excute("delete from " + imageService.getTableName()
					+ " where id = " + imageId);
		} else {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-10041");
			jsonErrorResponse.setErrorMessage("抱歉，照片id不能为空，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 保存照片
	 */
	@Action(value = "/SaveImage", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String SaveImage() {
		if (imageId == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-10031");
			jsonErrorResponse.setErrorMessage("抱歉，图片id参数为空，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		Map<String, Object> albumsImages = imageService.queryById(imageId);
		if (albumsImages == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-10033");
			jsonErrorResponse.setErrorMessage("抱歉，图片id参数非法，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		tags = (List<Map<String, Object>>) paramMap.get("tags");
		// if (tags == null) {
		// JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
		// jsonErrorResponse.setErrorCode("-10032");
		// jsonErrorResponse.setErrorMessage("抱歉，标签id参数为空，无法继续操作");
		// return renderJson(jsonErrorResponse);
		// }
		if (summary == null) {
			summary = "";
		}
		imageService.update("update " + imageService.getTableName()
				+ " set summary = '" + summary + "' where id = " + imageId);
		if (tags != null && tags.size() > 0) {
			for (int i = 0; i < tags.size(); i++) {
				Map<String, Object> tag = tags.get(i);
				Long tagId = Long.valueOf(tag.get("tagId") + "");
				Map<String, Object> params = new HashMap<String, Object>();
				params.put("imageId", imageId);
				params.put("tagId", tagId);
				Map<String, Object> tagBefore = albumsImageTagService
						.queryOneRow(SqlUtils.genderQuerySql(
								"man_base_albums_image_tags",
								SqlUtils.genderConditionsByType(params, "and")));
				if (tagBefore == null || tagBefore.size() == 0) {
					albumsImageTagService.add(SqlUtils.genderInsertSql(
							"man_base_albums_image_tags", params));
				}
			}
		}
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 上传照片
	 */
	@Action(value = "/UploadImage", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String UploadImage() {
		if (paramMap != null && paramMap.size() > 0) {
			if (userId == null && paramMap.get("userId") != null) {
				Object tmp = paramMap.get("userId");
				try {
					String[] tmpArr = (String[]) tmp;
					userId = Long.valueOf(tmpArr[0]);
				} catch (Exception e) {
					userId = Long.valueOf(paramMap.get("userId") + "");
				}
			}
			if (albumId == null && paramMap.get("albumId") != null) {
				Object tmp = paramMap.get("albumId");
				try {
					String[] tmpArr = (String[]) tmp;
					albumId = Long.valueOf(tmpArr[0]);
				} catch (Exception e) {
					albumId = Long.valueOf(paramMap.get("albumId") + "");
				}
			}
			if (images == null && paramMap.get("images") != null) {
				// try {
				// String[] tmp = (String[]) paramMap.get("images");
				// images = new ArrayList<Map<String, Object>>();
				// for (int i = 0; i < tmp.length; i++) {
				// String tmpStr = tmp[i];
				// tmpStr.replaceAll("(", "").replaceAll(")", "")
				// .replaceAll(";", "")
				// .replaceAll("image =", "\"image\" : ");
				// System.out.println(">>>>>>>  " + tmpStr);
				// images.add((Map<String, Object>) Json.fromJson(tmpStr));
				// }
				// } catch (Exception e0) {
				// e0.printStackTrace();
				try {
					images = (List<Map<String, Object>>) paramMap.get("images");
				} catch (Exception e) {
					e.printStackTrace();
					try {
						images = (List<Map<String, Object>>) Json
								.fromJson(paramMap.get("images") + "");
					} catch (Exception e2) {
						e2.printStackTrace();
						try {
							Map<String, Object>[] tmp = (Map<String, Object>[]) Json
									.fromJson(paramMap.get("images") + "");
							images = new ArrayList<Map<String, Object>>();
							for (int i = 0; i < tmp.length; i++) {
								images.add(tmp[i]);
							}
						} catch (Exception e3) {
							e3.printStackTrace();
							try {
								Map<String, Object>[] tmp = (Map<String, Object>[]) paramMap
										.get("images");
								images = new ArrayList<Map<String, Object>>();
								for (int i = 0; i < tmp.length; i++) {
									images.add(tmp[i]);
								}
							} catch (Exception e4) {
								e4.printStackTrace();
							}
						}
					}
					// }
				}
			}
			if (title == null && paramMap.get("title") != null) {
				Object tmp = paramMap.get("title");
				try {
					String[] tmpArr = (String[]) tmp;
					title = tmpArr[0];
				} catch (Exception e) {
					title = paramMap.get("title") + "";
				}
			}
			if (summary == null && paramMap.get("summary") != null) {
				Object tmp = paramMap.get("summary");
				try {
					String[] tmpArr = (String[]) tmp;
					summary = tmpArr[0];
				} catch (Exception e) {
					summary = paramMap.get("summary") + "";
				}
			}
		}
		if (userId == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-10011");
			jsonErrorResponse.setErrorMessage("抱歉，用户id参数为空，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		Map<String, Object> user = userService.queryOneRowFromDbOrCache(
				SqlUtils.genderQuerySql("man_view_baseuser_union", " userId = "
						+ userId, "score"), expire);
		if (user == null || user.size() == 0) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-32");
			jsonErrorResponse.setErrorMessage("抱歉，没有该用户的资料");
			return renderJson(jsonErrorResponse);
		}
		if (albumId != null) {
			Map<String, Object> album = albumsService.queryById(albumId);
			if (album == null || album.size() == 0) {
				JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
				jsonErrorResponse.setErrorCode("-10021");
				jsonErrorResponse.setErrorMessage("抱歉，相册id参数非法，无法继续操作");
				return renderJson(jsonErrorResponse);
			}
		} else {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-10022");
			jsonErrorResponse.setErrorMessage("抱歉，相册id不能为空，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		List<Long> imageIdList = new ArrayList<Long>();
		// images = (List<Map<String, Object>>) paramMap.get("images");
		System.out.println(">>>>> images.size() : " + images.size());
		if (images != null && images.size() > 0) {
			for (int i = 0; i < images.size(); i++) {
				byte[] imgByte = null;
				if (StringUtils.isEmpty(fomart)) {
					fomart = "jpg";
				}
				Map<String, Object> image = images.get(i);
				// TODO
				String fileName = new Date().getTime() + "-" + userId + "."
						+ fomart;
				String extPath = MyDateUtils.parseDateToStr("yyyyMMdd") + "/"
						+ fileName;
				String filePath = SystemConstants.UPLOAD_SERVER_PATH + extPath;
				OutputStream os = null;

				try {
					imgByte = Base64.decode(image.get("image") + "");
					File f = new File(filePath);
					// 如果文件不存在或者需要强制覆盖文件，则进行读取并写入
					if (!f.exists()) {
						File p = new File(f.getParent());
						if (!p.exists()) {
							p.mkdirs();
						}
						os = new FileOutputStream(new File(filePath));
						os.write(imgByte);
						// 这里调用，强制输出多个尺寸
						imageUtils.resetImgByWidth(filePath);
						Map<String, Object> paramMap2 = new HashMap<String, Object>();
						paramMap2.put("albumId", albumId);
						paramMap2.put("summary", summary);
						paramMap2.put("imageUrl",
								SystemConstants.UPLOAD_WEB_URL + extPath);
						paramMap2.put("userId", userId);
						Long imgId = imageService.add(SqlUtils.genderInsertSql(
								imageService.getTableName(), paramMap2));
						imageIdList.add(imgId);
					}
				} catch (Exception e) {
					e.printStackTrace();
					JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
					jsonErrorResponse.setErrorCode("-63");
					jsonErrorResponse
							.setErrorMessage("抱歉，base64转换错误，请重新尝试，保存失败");
					return renderJson(jsonErrorResponse);
				} finally {
					try {
						os.close();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		jsonSuccessResponse.getData().put("imageId", imageIdList);
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 删除相册
	 */
	@Action(value = "/RemoveAlbum", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String RemoveAlbum() {
		if (albumId != null) {
			Map<String, Object> album = albumsService.queryById(albumId);
			if (album == null || album.size() == 0) {
				JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
				jsonErrorResponse.setErrorCode("-10021");
				jsonErrorResponse.setErrorMessage("抱歉，相册id参数非法，无法继续操作");
				return renderJson(jsonErrorResponse);
			}
			albumsService.excute("delete from man_base_albums where id = "
					+ albumId);
		} else {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-10022");
			jsonErrorResponse.setErrorMessage("抱歉，相册id不能为空，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 保存相册
	 */
	@Action(value = "/SaveAlbum", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String SaveAlbum() {
		if (paramMap != null && paramMap.size() > 0) {
			if (userId == null && paramMap.get("userId") != null) {
				Object tmp = paramMap.get("userId");
				userId = Long.valueOf(tmp + "");
			}
		}
		if (userId == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-10011");
			jsonErrorResponse.setErrorMessage("抱歉，用户id参数为空，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		Map<String, Object> user = userService.queryOneRowFromDbOrCache(
				SqlUtils.genderQuerySql("man_view_baseuser_union", " userId = "
						+ userId), expire);
		if (user == null || user.size() == 0) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-32");
			jsonErrorResponse.setErrorMessage("抱歉，没有该用户的资料");
			return renderJson(jsonErrorResponse);
		}
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("userId", userId);
		paramMap.put("title", title);
		paramMap.put("isPrivate", isPrivate ? 0 : 1);
		if (albumId != null) {
			Map<String, Object> album = albumsService.queryById(albumId);
			if (album == null || album.size() == 0) {
				JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
				jsonErrorResponse.setErrorCode("-10021");
				jsonErrorResponse.setErrorMessage("抱歉，相册id参数非法，无法继续操作");
				return renderJson(jsonErrorResponse);
			}
			albumsService.update(SqlUtils.genderUpdateSql("man_base_albums",
					"id = " + albumId,
					SqlUtils.genderConditionsByType(paramMap, ",")));
		} else {
			albumId = albumsService.add(SqlUtils.genderInsertSql(
					"man_base_albums", paramMap));
		}
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("albumId", albumId);
		jsonSuccessResponse.setData(map);
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 获取收藏列表
	 */
	@Action(value = "/GetFavorite", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String GetFavorite() {
		if (paramMap != null && paramMap.size() > 0) {
			if (userId == null && paramMap.get("userId") != null) {
				Object tmp = paramMap.get("userId");
				userId = Long.valueOf(tmp + "");
			}
		}
		if (userId == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-10011");
			jsonErrorResponse.setErrorMessage("抱歉，用户id参数为空，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		Map<String, Object> user = userService.queryOneRowFromDbOrCache(
				SqlUtils.genderQuerySql("man_view_baseuser_union", " userId = "
						+ userId, "score"), expire);
		if (user == null || user.size() == 0) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-32");
			jsonErrorResponse.setErrorMessage("抱歉，没有该用户的资料");
			return renderJson(jsonErrorResponse);
		}
		Page page = new Page(
				pageNumber,
				pageLine,
				"select a.*,u.name as userName,u.imageUrl as authorImageUrl from man_base_article_collection as c,man_view_basearticle_union a,man_view_baseuser_union u where c.articleId = a.id and a.audit_id = u.userId and c.userId = "
						+ userId, expire, userAttentionService);
		List<Map<String, Object>> list = page.getList();
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				Map<String, Object> article = list.get(i);
				Long id = (Long) article.get("id");
				List<Map<String, Object>> imageList = imageService
						.queryListFromDbOrCache(
								"select * from " + imageService.getTableName()
										+ " where articleId = " + id, expire);
				article.put("images", imageList);
			}
		}
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("articles", list);
		jsonSuccessResponse.setData(map);
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 获取关注人列表
	 */
	@Action(value = "/GetFollowUser", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String GetFollowUser() {
		if (paramMap != null && paramMap.size() > 0) {
			if (userId == null && paramMap.get("userId") != null) {
				Object tmp = paramMap.get("userId");
				userId = Long.valueOf(tmp + "");
			}
		}
		if (userId == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-10011");
			jsonErrorResponse.setErrorMessage("抱歉，用户id参数为空，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		Map<String, Object> user = userService.queryOneRowFromDbOrCache(
				SqlUtils.genderQuerySql("man_view_baseuser_union", " userId = "
						+ userId, "score"), expire);
		if (user == null || user.size() == 0) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-32");
			jsonErrorResponse.setErrorMessage("抱歉，没有该用户的资料");
			return renderJson(jsonErrorResponse);
		}
		List<Map<String, Object>> userList = userAttentionService
				.queryListFromDbOrCache(
						"select u.*,u.groupId as type from man_base_user_attention as a,man_view_baseuser_union u  where u.userId = a.followUserId and a.userId = "
								+ userId, expire);
		removePasswordFromUser(userList);
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("users", userList);
		jsonSuccessResponse.setData(map);
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 上传用户背景图片
	 */
	@Action(value = "/UploadUserBackgroundImage", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String UploadUserBackgroundImage() {
		if (paramMap != null && paramMap.size() > 0) {
			if (userId == null && paramMap.get("userId") != null) {
				Object tmp = paramMap.get("userId");
				userId = Long.valueOf(tmp + "");
			}
			if (image == null && paramMap.get("image") != null) {
				Object tmp = paramMap.get("image");
				image = tmp + "";
			}
		}
		if (userId == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-51");
			jsonErrorResponse.setErrorMessage("抱歉，用户id为空");
			return renderJson(jsonErrorResponse);
		}
		Map<String, Object> user = userService.queryOneRow(SqlUtils
				.genderQuerySql("man_view_baseuser_union", " userId = "
						+ userId));
		if (user == null || user.size() == 0) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-52");
			jsonErrorResponse.setErrorMessage("抱歉，没有该用户的资料");
			return renderJson(jsonErrorResponse);
		}
		byte[] imgByte = null;
		if (StringUtils.isEmpty(fomart)) {
			fomart = "jpg";
		}
		// TODO
		String fileName = new Date().getTime() + "-" + userId + "." + fomart;
		String extPath = "/" + MyDateUtils.parseDateToStr("yyyyMMdd") + "/"
				+ fileName;
		String filePath = SystemConstants.UPLOAD_SERVER_PATH + extPath;
		OutputStream os = null;
		try {
			imgByte = Base64.decode(image);
			File f = new File(filePath);
			// 如果文件不存在或者需要强制覆盖文件，则进行读取并写入
			if (!f.exists()) {
				File p = new File(f.getParent());
				if (!p.exists()) {
					p.mkdirs();
				}
				os = new FileOutputStream(new File(filePath));
				os.write(imgByte);
				// 这里调用，强制输出多个尺寸
				imageUtils.resetImgByWidth(filePath);
			}
		} catch (Exception e) {
			e.printStackTrace();
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-53");
			jsonErrorResponse.setErrorMessage("抱歉，base64转换错误，请重新尝试，保存失败");
			return renderJson(jsonErrorResponse);
		} finally {
			try {
				os.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		boolean flag = userService.update(SqlUtils.genderUpdateSql(
				"man_base_user_field", " userId = " + userId,
				"backgroundImageUrl = '" + SystemConstants.UPLOAD_WEB_URL
						+ extPath + "'"));
		flag = userService.update(SqlUtils.genderUpdateSql(
				"man_base_user",
				" userId = " + userId,
				"update_time='"
						+ MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss")
						+ "'"));
		if (flag) {
			JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
			return renderJson(jsonSuccessResponse);
		} else {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-54");
			jsonErrorResponse.setErrorMessage("抱歉，更新图片失败");
			return renderJson(jsonErrorResponse);
		}
	}

	/**
	 * 上传用户头像
	 */
	@Action(value = "/UploadUserImage", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String UploadUserImage() {
		// System.out.println(">>userId : " + userId);
		// System.out.println(">>image : " + image);
		if (paramMap != null && paramMap.size() > 0) {
			if (userId == null && paramMap.get("userId") != null) {
				Object tmp = paramMap.get("userId");
				userId = Long.valueOf(tmp + "");
			}
			if (image == null && paramMap.get("image") != null) {
				Object tmp = paramMap.get("image");
				image = tmp + "";
			}
		}
		if (userId == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-51");
			jsonErrorResponse.setErrorMessage("抱歉，用户id为空");
			return renderJson(jsonErrorResponse);
		}
		Map<String, Object> user = userService.queryOneRow(SqlUtils
				.genderQuerySql("man_view_baseuser_union", " userId = "
						+ userId));
		if (user == null || user.size() == 0) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-52");
			jsonErrorResponse.setErrorMessage("抱歉，没有该用户的资料");
			return renderJson(jsonErrorResponse);
		}
		byte[] imgByte = null;
		if (StringUtils.isEmpty(fomart)) {
			fomart = "jpg";
		}
		// TODO
		String fileName = new Date().getTime() + "-" + userId + "." + fomart;
		String extPath = "/" + MyDateUtils.parseDateToStr("yyyyMMdd") + "/"
				+ fileName;
		String filePath = SystemConstants.UPLOAD_SERVER_PATH + extPath;
		OutputStream os = null;
		try {
			imgByte = Base64.decode(image);
			File f = new File(filePath);
			// 如果文件不存在或者需要强制覆盖文件，则进行读取并写入
			if (!f.exists()) {
				File p = new File(f.getParent());
				if (!p.exists()) {
					p.mkdirs();
				}
				os = new FileOutputStream(new File(filePath));
				os.write(imgByte);
				// 这里调用，强制输出多个尺寸
				imageUtils.resetImgByWidth(filePath);
			}
		} catch (Exception e) {
			e.printStackTrace();
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-53");
			jsonErrorResponse.setErrorMessage("抱歉，base64转换错误，请重新尝试，保存失败");
			return renderJson(jsonErrorResponse);
		} finally {
			try {
				os.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		boolean flag = userService.update(SqlUtils.genderUpdateSql(
				"man_base_user",
				" userId = " + userId,
				"imageUrl = '" + SystemConstants.UPLOAD_WEB_URL + extPath
						+ "',update_time='"
						+ MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss")
						+ "'"));
		if (flag) {
			JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
			return renderJson(jsonSuccessResponse);
		} else {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-54");
			jsonErrorResponse.setErrorMessage("抱歉，更新图片失败");
			return renderJson(jsonErrorResponse);
		}
	}

	/**
	 * 获取用户积分
	 */
	@Action(value = "/GetUserScore", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String GetUserScore() {
		if (paramMap != null && paramMap.size() > 0) {
			if (userId == null && paramMap.get("userId") != null) {
				Object tmp = paramMap.get("userId");
				userId = Long.valueOf(tmp + "");
			}
		}
		if (userId == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-10011");
			jsonErrorResponse.setErrorMessage("抱歉，用户id参数为空，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		Map<String, Object> user = userService.queryOneRowFromDbOrCache(
				SqlUtils.genderQuerySql("man_view_baseuser_union", " userId = "
						+ userId, "score"), expire);
		if (user == null || user.size() == 0) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-32");
			jsonErrorResponse.setErrorMessage("抱歉，没有该用户的资料");
			return renderJson(jsonErrorResponse);
		}
		removePasswordFromUser(user);
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		jsonSuccessResponse.setData(user);
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 获取用户资料
	 */
	@Action(value = "/GetUserInfo", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String GetUserInfo() {
		if (paramMap != null && paramMap.size() > 0) {
			if (userId == null && paramMap.get("userId") != null) {
				Object tmp = paramMap.get("userId");
				userId = Long.valueOf(tmp + "");
			}
		}
		if (userId == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-31");
			jsonErrorResponse.setErrorMessage("抱歉，用户id参数为空，无法继续操作");
			return renderJson(jsonErrorResponse);
		}
		Map<String, Object> user = userService.queryOneRowFromDbOrCache(
				"select *,groupId as type from man_view_baseuser_union where  userId = "
						+ userId, expire);
		if (user == null || user.size() == 0) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-32");
			jsonErrorResponse.setErrorMessage("抱歉，没有该用户的资料");
			return renderJson(jsonErrorResponse);
		}
		removePasswordFromUser(user);
		// 准备用户的相册信息
		List<Map<String, Object>> albumsList = albumsService.queryList(SqlUtils
				.genderQuerySql("man_base_albums", "userId = " + userId));
		if (albumsList == null) {
			albumsList = new ArrayList<Map<String, Object>>();
		}
		for (int i = 0; i < albumsList.size(); i++) {
			Map<String, Object> albums = albumsList.get(i);
			String albumsId = albums.get("id") + "";
			if (albumsId.trim().length() > 0 && !albumsId.trim().equals("null")) {
				List<Map<String, Object>> albumsImageList = imageService
						.queryList(SqlUtils.genderQuerySql(
								imageService.getTableName(), "albumId = "
										+ albumsId));
				albums.put("images", albumsImageList);
			}
		}
		user.put("albums", albumsList);
		// 准备用户的文章信息
		String addStr = "";
		// int userType = Integer.valueOf(user.get("userType") + "");
		// if (userType == ManConstants.USER_TYPE_DAREN.intValue()) {
		// addStr = " a.authorId = " + user.get("id") + " and ";
		// }
		String sqls = "select a.*,u.name as userName,u.imageUrl as authorImageUrl from man_view_basearticle_union as a,man_view_baseuser_union as u where a.authorId = u.userId and "
				+ addStr
				+ "authorId = "
				+ userId
				+ " order by a.top_time desc ,a.createDate desc";
		List<Map<String, Object>> articleList = articleService.queryList(sqls);
		if (articleList == null) {
			articleList = new ArrayList<Map<String, Object>>();
		}
		for (int i = 0; i < articleList.size(); i++) {
			Map<String, Object> artile = articleList.get(i);
			String artileId = artile.get("id") + "";
			if (artileId.trim().length() > 0 && !artileId.trim().equals("null")) {
				List<Map<String, Object>> artileImageList = imageService
						.queryList(SqlUtils.genderQuerySql(
								imageService.getTableName(), "articleId = "
										+ artileId));
				artile.put("images", artileImageList);
			}
		}
		user.put("articles", articleList);
		user.put("isAttention",
				isAttention(curUserId, Long.valueOf(user.get("userId") + "")));
		user.put("isSigned",
				isSigned(curUserId, Long.valueOf(user.get("userId") + "")));
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		jsonSuccessResponse.setData(user);
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 用户签到
	 */
	@SuppressWarnings("unchecked")
	@Action(value = "/Sign", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String Sign() {
		if (userId != null) {
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("userId", userId);
			Map<String, Object> user = userService
					.queryOneRowFromDbOrCache(
							SqlUtils.genderQuerySql("man_view_baseuser_union",
									SqlUtils.genderConditionsByType(paramMap,
											" and ")), expire);
			if (user == null || user.size() == 0) {
				JsonErrorResponse errorResponse = new JsonErrorResponse();
				errorResponse.setErrorCode("10001");
				errorResponse.setErrorMessage("该用户不存在，无法签到");
				return renderJson(errorResponse);
			}
			String today = MyDateUtils.parseDateToStr("yyyy-MM-dd");
			String nextday = MyDateUtils.parseDateToStr(MyDateUtils.addDate(1),
					"yyyy-MM-dd");
			Map<String, Object> paramMap2 = new HashMap<String, Object>();
			paramMap2.put("userId", userId);
			paramMap2.put("signTime >=", today);
			paramMap2.put("signTime <", nextday);
			List<Map<String, Object>> signList = userSignService
					.queryList(SqlUtils.genderQuerySql("man_base_user_sign",
							SqlUtils.genderConditionsByType(paramMap2, " and ")));
			if (signList != null
					&& signList.size() >= ManConstants.USER_SIGNTIME_MAX) {
				JsonErrorResponse errorResponse = new JsonErrorResponse();
				errorResponse.setErrorCode("10002");
				errorResponse.setErrorMessage("今日的签到次数已到，无法继续签到，请明天在来");
				return renderJson(errorResponse);
			}
			Map<String, Object> paramMap3 = new HashMap<String, Object>();
			paramMap3.put("userId", userId);
			paramMap3.put("signTime",
					MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss"));
			userSignService.add(SqlUtils.genderInsertSql("man_base_user_sign",
					paramMap3));
			JsonSuccessResponse successResponse = new JsonSuccessResponse();
			return renderJson(successResponse);
		}
		JsonErrorResponse errorResponse = new JsonErrorResponse();
		errorResponse.setErrorCode("10000");
		errorResponse.setErrorMessage("该用户不存在，无法签到");
		return renderJson(errorResponse);
	}

	/**
	 * 用户登录
	 */
	@SuppressWarnings("unchecked")
	@Action(value = "/Login", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String Login() {
		if (password == null) {
			password = "";
		}
		if (StringUtils.isEmpty(phoneNumber)) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-19");
			jsonErrorResponse.setErrorMessage("抱歉，手机号为空");
			return renderJson(jsonErrorResponse);
		}
		Map<String, Object> user = userService.queryOneRowFromDbOrCache(
				"select * from man_view_baseuser_union where (phoneNumber ='"
						+ phoneNumber + "' or userName = '" + phoneNumber
						+ "') limit 0,1", "0mn");
		if (user == null || user.size() == 0) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-18");
			jsonErrorResponse.setErrorMessage("抱歉，该用户不存在，请先注册");
			return renderJson(jsonErrorResponse);
			// 用户不存在，认为是注册
			// Map<String, Object> paramMap = new HashMap<String, Object>();
			// Map<String, Object> paramMap2 = new HashMap<String, Object>();
			// paramMap.put("userName", phoneNumber);
			// paramMap.put("phone", phoneNumber);
			// paramMap2.put("phoneNumber", phoneNumber);
			// paramMap.put("password", MD5Util.getMD5Lower(password));
			// paramMap2.put("score", 0);
			// paramMap2.put("scoreState", 0);
			// paramMap.put("name", "");
			// paramMap.put("imageUrl", "");
			// paramMap2.put("bwh", "");
			// paramMap2.put("constellation", "");
			// String now = MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss");
			// paramMap.put("createDate", now);
			// paramMap.put("update_time", now);
			// userId =
			// userService.add(SqlUtils.genderInsertSql("man_base_user",
			// paramMap));
			// paramMap2.put("userId", userId);
			// paramMap2.put("introduction", "");
			// userFieldService.add(SqlUtils.genderInsertSql(
			// "man_base_user_field", paramMap2));
			// user = userService.queryOneRowFromDbOrCache(SqlUtils
			// .genderQuerySql("man_view_baseuser_union", "userId = "
			// + userId), expire);
		} else {
			if (!(user.get("password") + "").equals(MD5Util
					.getMD5Lower(password))) {
				JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
				jsonErrorResponse.setErrorCode("-11");
				jsonErrorResponse.setErrorMessage("抱歉，密码错误");
				return renderJson(jsonErrorResponse);
			}
			userId = Long.valueOf(user.get("userId") + "");
		}
		userService.update("update " + userService.getTableName()
				+ " set lastlogin = '"
				+ MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss")
				+ "' where userId = " + userId);
		userFieldService.update("update " + userFieldService.getTableName()
				+ " set platform = " + platform + " where userId = " + userId);
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		jsonSuccessResponse.setData(user);
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 用户注册
	 */
	@SuppressWarnings("unchecked")
	@Action(value = "/Register", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String Register() {
		if (password == null) {
			password = "";
		}
		if (StringUtils.isEmpty(phoneNumber)) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-19");
			jsonErrorResponse.setErrorMessage("抱歉，手机号为空");
			return renderJson(jsonErrorResponse);
		}
		Map<String, Object> user = userService.queryOneRowFromDbOrCache(
				"select * from man_view_baseuser_union where (phoneNumber ='"
						+ phoneNumber + "' or userName = '" + phoneNumber
						+ "') limit 0,1", "0mn");
		if (user == null || user.size() == 0) {
			// 用户不存在，认为是注册
			Map<String, Object> paramMap = new HashMap<String, Object>();
			Map<String, Object> paramMap2 = new HashMap<String, Object>();
			paramMap.put("userName", phoneNumber);
			paramMap.put("phone", phoneNumber);
			paramMap2.put("phoneNumber", phoneNumber);
			paramMap.put("password", MD5Util.getMD5Lower(password));
			paramMap2.put("score", 0);
			paramMap2.put("scoreState", 0);
			paramMap.put("name", "");
			paramMap.put("imageUrl", "");
			paramMap2.put("bwh", "");
			paramMap2.put("constellation", "");
			String now = MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss");
			paramMap.put("createDate", now);
			paramMap.put("update_time", now);
			userId = userService.add(SqlUtils.genderInsertSql("man_base_user",
					paramMap));
			paramMap2.put("userId", userId);
			paramMap2.put("introduction", "");
			userFieldService.add(SqlUtils.genderInsertSql(
					"man_base_user_field", paramMap2));
			user = userService.queryOneRowFromDbOrCache(SqlUtils
					.genderQuerySql("man_view_baseuser_union", "userId = "
							+ userId), expire);
		} else {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-19");
			jsonErrorResponse.setErrorMessage("抱歉，该用户已存在");
			return renderJson(jsonErrorResponse);
		}
		userService.update("update " + userService.getTableName()
				+ " set lastlogin = '"
				+ MyDateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss")
				+ "' where userId = " + userId);
		userFieldService.update("update " + userFieldService.getTableName()
				+ " set platform = " + platform + " where userId = " + userId);
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		jsonSuccessResponse.setData(user);
		return renderJson(jsonSuccessResponse);
	}

	/**
	 * 保存用户信息 http://localhost:8080/manWear/phone/saveUser.shtml?userId=1&age=21
	 */
	@Action(value = "/SaveUser", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String SaveUser() {
		if (paramMap != null && paramMap.size() > 0) {
			if (userId == null && paramMap.get("userId") != null) {
				Object tmp = paramMap.get("userId");
				userId = Long.valueOf(tmp + "");
			}
		}
		if (userId == null) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-1");
			jsonErrorResponse.setErrorMessage("用户id不能为空");
			return renderJson(jsonErrorResponse);
		}
		Map<String, Object> paramMap = new HashMap<String, Object>();
		Map<String, Object> paramMap2 = new HashMap<String, Object>();
		if (!StringUtils.isEmpty(name)) {
			paramMap.put("name", name);
		}
		if (gender != null) {
			paramMap2.put("gender", gender);
		}
		if (age != null) {
			paramMap2.put("age", age);
		}
		if (!StringUtils.isEmpty(bwh)) {
			paramMap2.put("bwh", bwh);
		}
		if (!StringUtils.isEmpty(constellation)) {
			paramMap2.put("constellation", constellation);
		}
		if (paramMap.size() == 0) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-2");
			jsonErrorResponse
					.setErrorMessage("请检查参数，可能没有传入需要修改的选项信息内容，或者传入的值不符合相关类型");
			return renderJson(jsonErrorResponse);
		}
		boolean flag = userService.update(SqlUtils.genderUpdateSql(
				"man_base_user", "userId = " + userId,
				SqlUtils.genderConditionsByType(paramMap, ",")));
		flag = userService.update(SqlUtils.genderUpdateSql(
				"man_base_user_field", "userId = " + userId,
				SqlUtils.genderConditionsByType(paramMap2, ",")));
		if (flag) {
			JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
			return renderJson(jsonSuccessResponse);
		} else {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-2");
			jsonErrorResponse.setErrorMessage("更新失败");
			return renderJson(jsonErrorResponse);
		}
	}

	/**
	 * 获取启动广告
	 * 
	 * @return { success: true data: { imageUrl: string //图片网址 } }
	 */
	@SuppressWarnings("unchecked")
	@Action(value = "/GetSplashImage", interceptorRefs = @InterceptorRef("withoutAuthStack"))
	public String GetSplashImage() {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("is_used", 0);
		String key = "getSplashImage";
		Map<String, Object> img = (Map<String, Object>) Cache.get(key);
		if (img == null) {
			img = splashScreenService.queryOneRow(SqlUtils.genderQuerySql(
					"man_base_splashscreen",
					SqlUtils.genderConditionsByType(paramMap, " and ")
							+ " order by createDate desc"));
			if (img != null) {
				Cache.add(key, img, expire);
			}
		}
		if (img == null || img.size() == 0) {
			JsonErrorResponse jsonErrorResponse = new JsonErrorResponse();
			jsonErrorResponse.setErrorCode("-21");
			jsonErrorResponse.setErrorMessage("未能找到闪屏的图片信息");
			return renderJson(jsonErrorResponse);
		}
		JsonSuccessResponse jsonSuccessResponse = new JsonSuccessResponse();
		jsonSuccessResponse.getData().put("imageUrl", img.get("logo"));
		return renderJson(jsonSuccessResponse);
	}

	public void setParamMap(Map<String, Object> paramMap) {
		this.paramMap = paramMap;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setGender(Integer gender) {
		this.gender = gender;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	public void setBwh(String bwh) {
		this.bwh = bwh;
	}

	public void setConstellation(String constellation) {
		this.constellation = constellation;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setPlatform(String platform) {
		this.platform = platform;
	}

	public void setPageNumber(Integer pageNumber) {
		this.pageNumber = pageNumber;
	}

	public void setPageLine(Integer pageLine) {
		this.pageLine = pageLine;
	}

	public void setState(Integer state) {
		this.state = state;
	}

	public void setImage(String image) {
		this.image = image;
	}

	public void setFomart(String fomart) {
		this.fomart = fomart;
	}

	public void setAlbumId(Long albumId) {
		this.albumId = albumId;
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}

	public void setFollowUserId(Long followUserId) {
		this.followUserId = followUserId;
	}

	public void setValue(Integer value) {
		this.value = value;
	}

	public Boolean getValue() {
		return this.value.intValue() == 1;
	}

	public void setColumnId(Long columnId) {
		this.columnId = columnId;
	}

	public void setArticleId(Long articleId) {
		this.articleId = articleId;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public void setQuestionId(Long questionId) {
		this.questionId = questionId;
	}

	public void setImages(List<Map<String, Object>> images) {
		this.images = images;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	public void setIsPrivate(Boolean isPrivate) {
		this.isPrivate = isPrivate;
	}

	public void setTags(List<Map<String, Object>> tags) {
		this.tags = tags;
	}

	public void setImageId(Long imageId) {
		this.imageId = imageId;
	}

	public void setQuestId(Long questId) {
		this.questId = questId;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public void setGirlId(Long girlId) {
		this.girlId = girlId;
	}

	public void setScore(Integer score) {
		this.score = score;
	}

	public void setAnswerId(Long answerId) {
		this.answerId = answerId;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public void setDays(Integer days) {
		this.days = days;
	}

	public void setGirlCity(String girlCity) {
		this.girlCity = girlCity;
	}

	public void setValueNum(Integer valueNum) {
		this.valueNum = valueNum;
	}

	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}

	public void setCurUserId(Long curUserId) {
		this.curUserId = curUserId;
	}

	public void setBust(Integer bust) {
		this.bust = bust;
	}

	public void setWaistline(Integer waistline) {
		this.waistline = waistline;
	}

	public void setHip(Integer hip) {
		this.hip = hip;
	}

}
